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!");
}
}
}