Advertisement
selvalives

Untitled

Dec 10th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package com.nus.app1;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.RadioButton;
  9. import android.widget.RadioGroup;
  10. import android.widget.TextView;
  11.  
  12. public class HPCalcActivity extends Activity
  13. {
  14. EditText tcarprice,tdeposit,tinterest,tyears;
  15. TextView tinstallment;
  16. Button btncalc;
  17. Double carprice,deposit,interest,installment;
  18. RadioGroup rgyears;
  19. RadioButton rb;
  20. int years;
  21. public void onCreate(Bundle b)
  22. {
  23. super.onCreate(b);
  24. setContentView(R.layout.hpcalclayout);
  25. tcarprice=findViewById(R.id.tcarprice);
  26. tdeposit=findViewById(R.id.tdeposit);
  27. tinterest=findViewById(R.id.tinterest);
  28. tinstallment=findViewById(R.id.tinstallment);
  29. btncalc=findViewById(R.id.btncalc);
  30. rgyears=findViewById(R.id.rgyears);
  31. btncalc.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. carprice=Double.parseDouble(tcarprice.getText().toString());
  35. deposit=Double.parseDouble(tdeposit.getText().toString());
  36. interest=Double.parseDouble(tinterest.getText().toString());
  37. //years=Integer.parseInt(tyears.getText().toString());
  38. int selectedradio=rgyears.getCheckedRadioButtonId();
  39. rb=findViewById(selectedradio);
  40. years=Integer.parseInt(rb.getText().toString());
  41. installment=(((((carprice-deposit)*interest)/100)*years)+(carprice-deposit))/(years*12);
  42. tinstallment.setText(installment.toString());
  43. }
  44. });
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement