Activity 07: Object-Oriented Loan Calculator in Java

Verified

Added on  2025/05/01

|5
|449
|126
AI Summary
Desklib provides past papers and solved assignments for students. This is a solved Java programming assignment.
Document Page
MITS4002
OBJECT-ORIENTED SOFTWARE
DEVELOPMENT
Activity 07
Student ID:
Student full name:
Total Points (20 pts):
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1. Analysis
We will be creating a program which will return a list of output which includes the rate of
interest beginning from five per cent & increasing at a constant level with 0.125, monthly
and total payment will also be shown with the particular interval.
2. Design
First of all, a class named Activity07program will be created and in that amount
of loan and number of years will be declared as variables of the double datatype.
Secondly, declaring a function named Loan Display with 2 different parameters of
the double datatype of the amount of loan and number of years.
Now using a loop for iteration of the float datatypes of the initial rate variable. A
math class will be declared as pow to find the formula final value.
A new variable will be initialized as double new_Rate=initial_rate+1, double
num_of_months=12*num_of_yrs,double temp=(double)Math.pow(new_Rate,
-num_of_months) & double answer=(amount_of_loan*initial_rate)/(1-temp)
Scanner class will be used in the main function which will create a scanner object
for passing the input entered by the user to the function.
For all the unexpected inputs which will be wrong, exceptions will be handled and
the program will run smoothly.
The input statements are in the try statement to check for exceptions and if any
exceptions are caught then they will be directed to the catch statement.
The try checks for the exceptions as all the input statements are in it and
whenever an error occurs exception is handled by a catch statement.
Lastly, the method will display and print the final value of i using the print
function.
Document Page
3. Coding
package activity07program;
import java.util.Scanner;
public class Activity07program {
static double amount_of_loan;
static double num_of_yrs;
public static void Loan_Display(double amount_of_loan, double
num_of_yrs) {
System.out.println("Rate of Interest
"+"Monthly_Payment "+"Total_Payment ");
for (double i=5; i<=8; i+=0.125) {
float initial_rate=(float) (i*Math.pow(1200, -1));
double new_Rate= initial_rate+1;
double num_of_months=12*num_of_yrs;
double temp= (double) Math.pow(new_Rate, -num_of_months);
double answer= (amount_of_loan*initial_rate)/(1-temp);
System.out.println(i+"%"+" "+answer+"
"+answer*12*num_of_yrs);
}
}
public static void main(String [] main) {
Scanner q=new Scanner (System.in);
try {
System.out.println("Enter Amount for the loan = ");
double amount_of_loan=q.nextDouble();
System.out.println("Enter total no. of yrs = ");
double num_of_yrs=q.nextDouble();
Loan_Display(amount_of_loan,num_of_yrs);
Document Page
}
catch (Exception r) {
System.out.println(r);
main(null);
}}}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4. Output screenshot
5. Testing
The amount of loan is first entered if the value is of right data type, then the
program runs smoothly but if the value is not correct or the expected one, an
exception will be thrown and the program will be returned to main.
The same step followed for the number of years...
Finally, all the checked values will get used in the Loan_Display method with the
output coming as the final answer and printed.
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]