Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.marta.prob3;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import java.text.DecimalFormat;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void onClick(View view){
- int capital_value = Integer.parseInt((((EditText)findViewById(R.id.capital_value_id)).getText().toString()));
- int interest_rate = Integer.parseInt((((EditText)findViewById(R.id.interet_rate_id)).getText().toString()));
- int loan_duration = Integer.parseInt((((EditText)findViewById(R.id.loan_durantion_id)).getText().toString()));
- DecimalFormat df2 = new DecimalFormat(".##");
- System.out.println("capital_value " + capital_value);
- System.out.println("interest_rate " + interest_rate);
- System.out.println("loan_duration " + loan_duration);
- double value = ((double)((double)interest_rate/100)/12);
- System.out.println("value " + value);
- double temp = Math.pow((1 + value), loan_duration);
- System.out.println("temp " + temp);
- double monthly = (capital_value * ((value * temp) / (temp - 1)));
- System.out.println("montlhy " + monthly);
- String total_payment = Integer.toString((int) monthly * loan_duration);
- String monthly_payment = df2.format(monthly);
- System.out.println("monthly_payment " + monthly_payment);
- System.out.println("total_payment " + total_payment);
- ((EditText)findViewById(R.id.monthly_payment_id)).setText(monthly_payment);
- ((EditText)findViewById(R.id.total_payment_id)).setText(total_payment);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement