Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nus.app1;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- public class HPCalcActivity extends Activity
- {
- EditText tcarprice,tdeposit,tinterest,tyears;
- TextView tinstallment;
- Button btncalc;
- Double carprice,deposit,interest,installment;
- RadioGroup rgyears;
- RadioButton rb;
- int years;
- public void onCreate(Bundle b)
- {
- super.onCreate(b);
- setContentView(R.layout.hpcalclayout);
- tcarprice=findViewById(R.id.tcarprice);
- tdeposit=findViewById(R.id.tdeposit);
- tinterest=findViewById(R.id.tinterest);
- tinstallment=findViewById(R.id.tinstallment);
- btncalc=findViewById(R.id.btncalc);
- rgyears=findViewById(R.id.rgyears);
- btncalc.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- carprice=Double.parseDouble(tcarprice.getText().toString());
- deposit=Double.parseDouble(tdeposit.getText().toString());
- interest=Double.parseDouble(tinterest.getText().toString());
- //years=Integer.parseInt(tyears.getText().toString());
- int selectedradio=rgyears.getCheckedRadioButtonId();
- rb=findViewById(selectedradio);
- years=Integer.parseInt(rb.getText().toString());
- installment=(((((carprice-deposit)*interest)/100)*years)+(carprice-deposit))/(years*12);
- tinstallment.setText(installment.toString());
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement