Advertisement
selvalives

Untitled

Aug 31st, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package com.nsu.hpcalc;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.ArrayAdapter;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.Spinner;
  10. import android.widget.TextView;
  11.  
  12. public class calcactivity extends Activity
  13. {
  14. EditText tcarprice,tinterest,tdownpayment;
  15. TextView tinstallment;
  16. Button btncalc;
  17. Spinner syears;
  18. public void onCreate(Bundle b)
  19. {
  20. super.onCreate(b);
  21. setContentView(R.layout.calclayout);
  22. tcarprice=findViewById(R.id.tcarprice);
  23. tinterest=findViewById(R.id.tinterest);
  24. tdownpayment=findViewById(R.id.tdownpayment);
  25. tinstallment=findViewById(R.id.tinstallment);
  26. btncalc=findViewById(R.id.btncalculate);
  27. syears=findViewById(R.id.syears);
  28. Integer[] years = new Integer[]{1,2,3,4,5,6,7,8,9};
  29. ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_spinner_item, years);
  30. syears.setAdapter(adapter);
  31. btncalc.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. double carprice,interest,downpayment,installment;
  35. int years;
  36. carprice=Double.parseDouble(tcarprice.getText().toString());
  37. interest=Double.parseDouble(tinterest.getText().toString());
  38. downpayment=Double.parseDouble(tdownpayment.getText().toString());
  39. years=Integer.parseInt(syears.getSelectedItem().toString());
  40. installment=(((((carprice-downpayment)*interest)/100)*years)+(carprice-downpayment))/(years*12);
  41. tinstallment.setText(String.valueOf(installment));
  42. }
  43. });
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement