Question

Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

Program Requirements

·         The program prompts the user to enter a loan amount and an interest rate.

·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount.
Then, it displays the formatted results to the user.

·         The application prompts the user to continue.

·         The program stops prompting the user for values after taking 3 loan amounts.

·         The application calculates and displays the total loan and interest amount and ends the program

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.

Instructions

·         Use double variables for the loan amounts, interest rate, and interest amounts.

· You can use concatenation (use '+') to format and display the loan amount, interest rate, and total interest.

·         The application should continue only if the user enters “y” or “Y” to continue. Use equalsIgnoreCase() to test the strings entered by the user.

·         If the user has entered 3 loans, then set the while loop condition to “n” and end the while loop without prompting the user to continue.

·         After the loop, calculate and display the total loan and interest amount.

  • //DBPM FORMAT TEMPLATE

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("\nWould 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("\nTotal loan : " + /*get the total Amt for the Loan obj */ );
System.out.println("Total interest : " + /*get the interest Amount for the Loan obj */ );
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//if any error encounters or changes needed please do comment

//please thumbs up if it helps

//Code

import java.util.Scanner;

public class Loan {

// create the private double attributes : loanAmt, interestRate, interestAmount,

private double loanAmt, interestRate, interestAmount;

// totalAmt

private double totalAmt;

// create a default construction to initialize all of the attributes

public Loan() {

loanAmt = 0;

interestRate = 0;

interestAmount = 0;

totalAmt = 0;

}

// create a setter for each attribute

public void set_loanAmt(double loanAmt) {

this.loanAmt = loanAmt;

}

public void set_interestRate(double interestRate) {

this.interestRate = interestRate;

}

// create a getter for each attribute

public double get_loanAmt() {

return this.loanAmt;

}

public double get_interestRate() {

return this.interestRate;

}

public double get_totalAmt() {

return this.totalAmt;

}

public double get_interestAmount() {

return this.interestAmount;

}

// complete the calculateLoan method

public void calculateLoan() {

System.out.println("loan amount : $" + this.loanAmt);

System.out.println("interest rate: " + this.interestRate*100 + "%");

System.out.println(

"interest : $" + this.loanAmt * this.interestRate/* calculate the interest rate for the loanAmt */ );

// calculate the cumlative interestAmount

interestAmount += this.loanAmt * this.interestRate;

// compute the cumlative loanAmt

totalAmt += this.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

Loan obj=new Loan();

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

obj.set_loanAmt(loanvalue);

//use the setter to set the interestRate with the interest for the Loan obj

obj.set_interestRate(interest);

//call the calculateLoan method for the Loan obj

obj.calculateLoan();

System.out.print("\nWould 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("\nTotal loan : $" +obj.get_totalAmt() /*get the total Amt for the Loan obj */ );

System.out.println("Total interest : $" +obj.get_interestAmount() /*get the interest Amount for the Loan obj */ );

}

}

Output:

Add a comment
Know the answer?
Add Answer to:
Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • If I enter a negative value the program throws an error and the withdrawal amount is...

    If I enter a negative value the program throws an error and the withdrawal amount is added to the balance please help me find why? public abstract class BankAccount { private double balance; private int numOfDeposits; private int numOfwithdrawals; private double apr; private double serviceCharge; //Create getter and setter methods public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public int getNumOfDeposits() { return numOfDeposits; } public void setNumOfDeposits(int numOfDeposits) { this.numOfDeposits =...

  • Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3:...

    Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...

  • I am creating a program where a user will enter in a price amount. And then...

    I am creating a program where a user will enter in a price amount. And then the program will determine how many 20, 10, 5, 1, etc.. they get back. I keep getting "error: unexpected type" in my findValue method. Not too sure why I am getting this. There also might be more bugs in there that I am not aware of because it wont compile. Any help is appreciated. Here is my code: import java.util.Scanner; public class prac1 {...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

  • import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables...

    import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables int creditScore; double loanAmount,interestRate,interestAmount; final double I_a = 5.56,I_b = 6.38,I_c = 7.12,I_d = 9.34,I_e = 12.45,I_f = 0; String instructions = "This program calculates annual interest\n"+"based on a credit score.\n\n"; String output; Scanner input = new Scanner(System.in);// for receiving input from keyboard // get input from user System.out.println(instructions ); System.out.println("Enter the loan amount: $"); loanAmount = input.nextDouble(); System.out.println("Enter the credit score: "); creditScore...

  • Write a program that prompts the user for a positive integer, n, and then prints a...

    Write a program that prompts the user for a positive integer, n, and then prints a following shape of stars using nested for loop, System.out.print(“*”);, and System.out.println();. Example1: Enter a positive integer: 3 * * * * * * * * * Example2: Enter a positive integer: 5 * * * * * * * * * * * * * * * * * * * * * * * * * JAVA LANGUAGE!!

  • public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc...

    public static void main(String[] args) {         System.out.println("Welcome to the Future Value Calculator\n");         Scanner sc = new Scanner(System.in);         String choice = "y";         while (choice.equalsIgnoreCase("y")) {             // get the input from the user             System.out.println("DATA ENTRY");             double monthlyInvestment = getDoubleWithinRange(sc,                     "Enter monthly investment: ", 0, 1000);             double interestRate = getDoubleWithinRange(sc,                     "Enter yearly interest rate: ", 0, 30);             int years = getIntWithinRange(sc,                     "Enter number of years: ", 0, 100);             System.out.println();            ...

  • Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a...

    Write a C++ program that prompts a user to enter a temperature in Fahrenheit as a real number. After the temperature is entered display the temperature in Celsius. Your program will then prompt the user if they want to continue. If the character n or N is entered the program will stop; otherwise, the program will continue. After your program stops accepting temperatures display the average of all the temperatures entered in both Fahrenheit and Celsius. Be sure to use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT