MITS4002 Object-Oriented Software Development: Comparing Loans

Verified

Added on  2022/08/21

|4
|439
|11
Homework Assignment
AI Summary
This assignment solution presents a Java program designed to compare loan options, addressing the requirements of the MITS4002 Object-Oriented Software Development course. The program takes user inputs for loan amount and loan period and calculates the monthly and total payments for interest rates ranging from 5% to 8%, incrementing by 1/8. The solution includes the complete Java code, along with design considerations, coding implementation, and testing strategies. The design phase focuses on identifying the methods needed for calculation, and the coding section provides the Java code with input validation to handle incorrect input values. Testing involves evaluating the program with both positive and negative inputs to ensure accurate results and error handling. The output is formatted to display interest rates, monthly payments, and total payments, as demonstrated in the sample output provided in the problem description. This solution offers a comprehensive understanding of loan calculation principles and object-oriented programming techniques in Java.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Design:
The first step for solving the problem is to identify how many methods are used to compute the
desired output. In this program, there is only one method that is used for computing the monthly
loan amount. In this program, three variables are used for user input; the variables are amount,
year and rate. Based on the user input, the program computes monthly and total payment amount.
Coding:
import java.util.Scanner;
public class ComparingLoans {
public static void main(String[] args) {
// TODO Auto-generated method stub
double amount=0.0;
int yr=0;
double rate=5;
Scanner sc=new Scanner(System.in);
System.out.println("-----------------");
System.out.println("Comparing Loans");
System.out.println("-----------------");
System.out.println("Loan Amount: ");
amount=sc.nextDouble();
System.out.println("Number of Years");
yr=sc.nextInt();
if(amount>0 && yr>=0) {
System.out.printf("%-1s%20s%20s\n", "Interest Rate", "Monthly Payment",
"Total Payment");
for (; rate <= 8.00; rate += 0.125) {
double monthlyInterestRate = rate / 1200;
double monthlyPayment = amount* monthlyInterestRate/ (1 - 1 / Math.pow(1 +
monthlyInterestRate,yr * 12));
double totalPayment = monthlyPayment * 12 * yr;
System.out.println("------------------------------------------------");
System.out.printf("%-1.3f%s%17.2f%24.2f \n", rate,"%", ((int)
(monthlyPayment * 100) / 100.0),((int) (totalPayment * 100) / 100.0));
}
}
else {
System.out.println("Enter a valid details");
}
}
}
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Document Page
Output screenshot:
Screenshot-1
Document Page
Screenshot-2
Testing:
Both negative and positive values are used to test the above program and the program gives the
optimal output. The above program is for comparing loan amount so the amount and the year
never be zero or negative if the user gives such input the program gives an error message- ‘Enter
a valid detail’ and the above program is terminated.
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]