In: Computer Science
IN ANDROID STUDIO, you will create a mortgage calculator app that allows the user to enter a purchase price, down-payment amount, and an interest rate.
Based on these values, the app should calculate the loan amount (purchase price minus down payment) and display the monthly payment for 10, 20, and 30-year loans.
Allow the user to select a custom loan duration (in years) by using a SeekBar and display the monthly payment for that custom loan duration.
Assignment deliverables (all in a ZIP file):
A screenshot showing the execution of your application.
A detailed overview of the steps taken to complete your application.
The Project folder containing all source code for your application.
MainActivity.java
package com.example.loancalculator; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.SeekBar; import android.widget.Toast; public class MainActivity extends AppCompatActivity { Button btncalculate,btnreset; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btncalculate =(Button) findViewById(R.id.btncalculate); btncalculate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText txtpurchaseAmmount=(EditText) findViewById(R.id.txtpurchaseAmmount); EditText txtintrest=(EditText) findViewById(R.id.txtintrest); EditText txtdownPayment=(EditText) findViewById(R.id.txtdownPayment); EditText txttotal=(EditText) findViewById(R.id.txttotal); SeekBar SeekMonth = (SeekBar) findViewById(R.id.yearseekBar); int purchaseAmount=Integer.parseInt(txtpurchaseAmmount.getText().toString()); int downPayment=Integer.parseInt(txtdownPayment.getText().toString()); int rate=Integer.parseInt(txtintrest.getText().toString()); int period=SeekMonth.getProgress(); // here we calculate ammount Toast.makeText(getApplicationContext(),Integer.toString(period)+" Years you Select",Toast.LENGTH_LONG).show(); int totalpay=purchaseAmount+((purchaseAmount*rate*(period/12))/100); int monthlypay=(downPayment-(totalpay/12))/period; txttotal.setText(Integer.toString(monthlypay)+" in years "+Integer.toString(period)); } }); btnreset =(Button) findViewById(R.id.btnreset); btnreset.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText txtpurchaseAmmount=(EditText) findViewById(R.id.txtpurchaseAmmount); EditText txtintrest=(EditText) findViewById(R.id.txtintrest); EditText txtdownPayment=(EditText) findViewById(R.id.txtdownPayment); EditText txttotal=(EditText) findViewById(R.id.txttotal); txtintrest.setText(""); txtpurchaseAmmount.setText(""); txtdownPayment.setText(""); txttotal.setText(""); } }); } }
--------------------------------------------------------------------------------------------------------------------
activity_main.xml
xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" tools:context=".MainActivity"> android:id="@+id/txttop2" android:layout_width="401dp" android:layout_height="64dp" android:layout_marginBottom="4dp" android:layout_x="25dp" android:layout_y="26dp" android:background="#00F5F3F3" android:text="Loan Calculator !" android:textColor="#0A0A0A" android:textSize="40sp" app:fontFamily="sans-serif-medium" /> android:id="@+id/txttop" android:layout_width="182dp" android:layout_height="64dp" android:layout_marginBottom="4dp" android:layout_x="31dp" android:layout_y="556dp" android:background="#00F5F3F3" android:text="Monthly Pay :" android:textColor="#0A0A0A" android:textSize="25sp" app:fontFamily="sans-serif-medium" />
-----------------------------------------------------------------------------------------------------------
output Screen Shot