栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

最简单的房贷计算器

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

最简单的房贷计算器





    

        


            


            

                

                

                
            

            

                

                

                
            

        

        

            
package com.example.house;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText Commercial_Loan;
    private EditText Provident_Fund;
    private EditText All;
    private EditText Year;
    private EditText Month;
    Integer RadioGroup_Flag;//年份标识
    private RadioGroup chosen_group;
    private RadioButton year1;
    private RadioButton year2;
    private RadioButton year3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //确定按钮
        View btn_submit = findViewById(R.id.button);
        //单选年份
        chosen_group = (RadioGroup) findViewById(R.id.ChosenYears);
        year1 = (RadioButton) findViewById(R.id.radioButton1);
        year2 = (RadioButton) findViewById(R.id.radioButton2);
        year3 = (RadioButton) findViewById(R.id.radioButton3);
        Commercial_Loan = (EditText) findViewById(R.id.Number1);//商业保险结果集
        Provident_Fund = (EditText) findViewById(R.id.Number2);//公积金
        All = (EditText) findViewById(R.id.Number3);//所有费用
        Year = (EditText) findViewById(R.id.Number4);//每年偿还
        Month = (EditText) findViewById(R.id.Number5);//每月偿还

        //添加事件监听器
        btn_submit.setOnClickListener(this);
        //为radioGroup设置一个监听器:setOnCheckedChanged()
        //chosen_group.setOnCheckedChangeListener((RadioGroup.OnCheckedChangeListener) this);
    }






    //监听事件,上面implements View.OnClickListener后必须重写onClick函数实现
    @Override
    public void onClick(View view) {
        int Number_Com = Integer.parseInt(Commercial_Loan.getEditableText().toString().trim());
        int Number_Fund = Integer.parseInt(Provident_Fund.getEditableText().toString().trim());
        int id = chosen_group.getCheckedRadioButtonId();
        int year_id = id%10;
        //设置5年商贷5个点,公积金3个点 ,10年商贷4个点,公积金2个点 , 20年商贷3个点,公积金1个点。
        if(year_id == 8){
            Double money_all = Number_Com*1.25+Number_Fund*1.15;
            All.setText(String.valueOf(money_all));
            Double money_yaer = money_all/5;
            Year.setText(String.valueOf(money_yaer));
            Double money_month = money_all/60;
            Month.setText(String.valueOf(money_month));
        }else if(year_id ==9){
            Double money_all = Number_Com*1.4+Number_Fund*1.2;
            All.setText(String.valueOf(money_all));
            Double money_yaer = money_all/10;
            Year.setText(String.valueOf(money_yaer));
            Double money_month = money_all/120;
            Month.setText(String.valueOf(money_month));
        }else if(year_id ==0){
            Double money_all = Number_Com*1.6+Number_Fund*1.2;
            All.setText(String.valueOf(money_all));
            Double money_yaer = money_all/20;
            Year.setText(String.valueOf(money_yaer));
            Double money_month = money_all/240;
            Month.setText(String.valueOf(money_month));
        }else{
            All.setText(String.valueOf(id));
            Year.setText(String.valueOf(year_id));
            Month.setText("Wrong!");
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/346538.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号