Question
Example Output Welcome to the Interest Calculator Enter loan amount: 520000 Enter interest rate: . 05375 Loan amount: $520,000.00 Interest rate: 5.375% Interest: $27,950.00 Would
Example Output
Welcome to the Interest Calculator
Enter loan amount: 520000
Enter interest rate: . 05375
Loan amount: $520,000.00
Interest rate: 5.375%
Interest: $27,950.00
Would you like to enter another loan amount? (y/n): y
Enter loan amount: 4944.5
Enter interest rate: .01
Loan amount: $4,944.50
Interest rate : 1%
Interest : $49.45
Would you like to enter another loan amount? (y/n): n
Total loan = $524944.50
Total interest = $27999.45
Thank you.
//Loan.java Program
public class Loan { //create the private double attributes : loanAmt, interestRate, interestAmount, totalAmt //create a default construction to initialize all of the attributes //create a setter for each attribute //create a getter for each attribute //complete the calculateLoan method public void calculateLoan() { System.out.println("loan amount : " + this.loanAmt); System.out.println("interest rate: " + (/*convert the decimal to a whole number */ + "%"); System.out.println("interest : " + (/*calculate the interest rate for the loanAmt */ ) ) ; //calculate the cumlative interestAmount //compute the cumlative loanAmt } public static void main(String[] args) { String flag=""; int counter=0; double loanvalue=0.0; double interest = 0.0; System.out.println("Welcome to the Interest Calculator"); //create a Loan called obj Scanner keyboard = new Scanner(System.in); do { System.out.print("Enter loan amount : "); loanvalue = keyboard.nextDouble(); System.out.print("Enter interest rate: "); interest = keyboard.nextDouble(); //use the setter to set the loanAmt with the loanvalue for the Loan obj //use the setter to set the interestRate with the interest for the Loan obj //call the calculateLoan method for the Loan obj System.out.print(" Would you like to enter another loan amount? (y/n):"); Scanner input = new Scanner(System.in); flag = input.nextLine();
if (++counter >=3) flag="n"; } while ( flag.equalsIgnoreCase("Y")); System.out.println(" Total loan : " + /*get the total Amt for the Loan obj */ ); System.out.println("Total interest : " + /*get the interest Amount for the Loan obj */ ); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started