Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package com.example.marta.prob3;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7.  
  8. import java.text.DecimalFormat;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16. }
  17.  
  18. public void onClick(View view){
  19. int capital_value = Integer.parseInt((((EditText)findViewById(R.id.capital_value_id)).getText().toString()));
  20. int interest_rate = Integer.parseInt((((EditText)findViewById(R.id.interet_rate_id)).getText().toString()));
  21. int loan_duration = Integer.parseInt((((EditText)findViewById(R.id.loan_durantion_id)).getText().toString()));
  22.  
  23. DecimalFormat df2 = new DecimalFormat(".##");
  24.  
  25. System.out.println("capital_value " + capital_value);
  26. System.out.println("interest_rate " + interest_rate);
  27. System.out.println("loan_duration " + loan_duration);
  28.  
  29. double value = ((double)((double)interest_rate/100)/12);
  30. System.out.println("value " + value);
  31. double temp = Math.pow((1 + value), loan_duration);
  32. System.out.println("temp " + temp);
  33. double monthly = (capital_value * ((value * temp) / (temp - 1)));
  34. System.out.println("montlhy " + monthly);
  35. String total_payment = Integer.toString((int) monthly * loan_duration);
  36. String monthly_payment = df2.format(monthly);
  37.  
  38. System.out.println("monthly_payment " + monthly_payment);
  39. System.out.println("total_payment " + total_payment);
  40.  
  41. ((EditText)findViewById(R.id.monthly_payment_id)).setText(monthly_payment);
  42. ((EditText)findViewById(R.id.total_payment_id)).setText(total_payment);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement