public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //Initializing integers and doubles. int months; int balance; double balanceRemaining; double interest; double interest Paid; double principalPaid; double minimumRate; double minimumPaid; int monthsRemaining; int user Input; //Asking for user to input minimumPaid System.out.println("Enter an amount that is not below 120: "); minimumPaid = scnr.nextDouble(); System.out.println(); //If user enters an amount less than 120, they're prompted to reenter a supported amount. if (minimumPaid < 120) { System.out.println("Invalid amount, please re-enter."); minimumPaid = scnr.nextDouble(); } //Initializing values for the following equations. balance = 6000; interest = 0.18; minimumRate = 0.02; months = 12; monthsRemaining = 11; //Calculating values for interest Paid, principlePaid and balance remaining. interest Paid = interest / months * balance; principalPaid = minimumPaid - interest Paid; balanceRemaining = balance - principalPaid; //If minimumPaid is greater than 119 & greater than/equal to 120, output balanceRemaining. if (minimumPaid > 119 && minimumPaid >= 120) { System.out.println("Debt amount: $" + balance); System.out.println("If the minimum payment is: $" + minimumPaid + "0"); System.out.println("Balance remaining after one month: $" + balanceRemaining + "0"); System.out.println(); //Calculating balanceRemaining after 2 months. for (int i = 0; i < monthsRemaining; ++i) { balanceRemaining = balanceRemaining - minimumPaid + interestPaid; if (i == 0) { System.out.printf("Balance after two months: $%.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 3 months. if (i == 1) { System.out.printf("Balance after three months: $%.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 4 months. if (i == 2) { System.out.printf("Balance after four months: $ %.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 5 months. if (i == 3) { System.out.printf("Balance after five months $ %.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 6 months. if (i == 4) { System.out.printf("Balance after six months: $%.2f", balanceRemaining); System.out.println();

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please help.

This program is in Java. I'm trying to have the output for "your debt will be paid off in xyz years" output as 7 years with the below calculations, not 4 years. What is wrong with my calculations? How do I make the output 7 years instead of 4? Equations and decription of program provided below, as well as images of the actual code.

You made a $6,000 purchase for a used car using your approved credit card. The card comes with an 18%
annual interest rate, and 2% minimum monthly payment rate. Below are the equations I used in the program.


 Minimum monthly payment = Minimum monthly payment rate x Balance
 Interest Paid = Annual interest rate / 12 months x Balance
 Principal paid = Minimum monthly payment – Interest paid
Remaining Balance = Balance – principal paid


For 1st month, I computed the minimum monthly payment by taking 2% of the balance as follows

 Minimum monthly payment = .02 x $6000 = $120.00 

the Annual interest rate that was given earlier. I divided it by 12, to get the monthly rate.
Interest paid = .18/12.0 x $6000 = $90.00
Principal paid = $120.00 - $90.00 = $30.00 

Remaining balance = $6000.00 – $30.00 = $5,970.00 

principalPaid is supposed to decrease as the person pays off their debt, according to the instructions given to me. I'm not sure if that is affecting the output of my statement or not. Please help.

//Calculating balanceRemaining after 7 months.
if (i ==5) {
System.out.printf("Balance after seven months: $%.2f", balanceRemaining);
System.out.println();
//Calculating balanceRemaining after 8 months.
if (i = 6) {
System.out.printf("Balance after eight months: $ %.2f", balanceRemaining);
System.out.println();
}
//Calculating balanceRemaining after 9 months.
if (i == 7) {
System.out.printf("Balance after nine months: $%.2f", balanceRemaining);
System.out.println();
}
//Calculating balanceRemaining after 10 months.
if (i = 8) {
System.out.printf("Balance after ten months: $%.2f", balanceRemaining);
System.out.println();
}
}
//Calculating balanceRemaining after 11 months.
if (i = 9) {
System.out.printf("Balance after eleven months: $ %.2f", balanceRemaining);
System.out.println();
}
}
}
//Calculating balanceRemaining after 12 months.
if (i == 10) {
System.out.printf("Balance after twelve months: $ %.2f", balanceRemaining);
System.out.println();
//Calculating value of balanceRemaining after a year.
System.out.printf("Balance remaining after a year: $ %.2f", balanceRemaining);
System.out.println();
}
}
//If minimumPaid is greater than 119 & greater than/equal to 120, proceed.
if (minimumPaid > 119 && minimumPaid >= 120) {
int years = 1;
int i;
//Calculating int amount of years it'll take to pay off balanceRemaining.
for (i = 0; i >= 0; ++i) {
balance = balance - (int) minimumPaid;
if (balance == 0) {
System.out.printf("Your debt will be paid off in: %.2f", (double) years / 12);
System.out.print(" years" );
break;
} else {
}
}
}
years years + 1;
scnr.close();
}
//End of Program
Transcribed Image Text://Calculating balanceRemaining after 7 months. if (i ==5) { System.out.printf("Balance after seven months: $%.2f", balanceRemaining); System.out.println(); //Calculating balanceRemaining after 8 months. if (i = 6) { System.out.printf("Balance after eight months: $ %.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 9 months. if (i == 7) { System.out.printf("Balance after nine months: $%.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 10 months. if (i = 8) { System.out.printf("Balance after ten months: $%.2f", balanceRemaining); System.out.println(); } } //Calculating balanceRemaining after 11 months. if (i = 9) { System.out.printf("Balance after eleven months: $ %.2f", balanceRemaining); System.out.println(); } } } //Calculating balanceRemaining after 12 months. if (i == 10) { System.out.printf("Balance after twelve months: $ %.2f", balanceRemaining); System.out.println(); //Calculating value of balanceRemaining after a year. System.out.printf("Balance remaining after a year: $ %.2f", balanceRemaining); System.out.println(); } } //If minimumPaid is greater than 119 & greater than/equal to 120, proceed. if (minimumPaid > 119 && minimumPaid >= 120) { int years = 1; int i; //Calculating int amount of years it'll take to pay off balanceRemaining. for (i = 0; i >= 0; ++i) { balance = balance - (int) minimumPaid; if (balance == 0) { System.out.printf("Your debt will be paid off in: %.2f", (double) years / 12); System.out.print(" years" ); break; } else { } } } years years + 1; scnr.close(); } //End of Program
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
//Initializing integers and doubles.
int months;
int balance;
double balanceRemaining;
double interest;
double interest Paid;
double principalPaid;
double minimumRate;
double minimumPaid;
int monthsRemaining;
int userInput;
//Asking for user to input minimumPaid
System.out.println("Enter an amount that is not below 120: ");
minimumPaid = scnr.nextDouble();
System.out.println();
//If user enters an amount less than 120, they're prompted to reenter a supported amount.
if (minimumPaid < 120) {
System.out.println("Invalid amount, please re-enter.");
minimumPaid = scnr.nextDouble();
}
//Initializing values for the following equations.
balance 6000;
interest = 0.18;
minimumRate = 0.02;
months = 12;
monthsRemaining = 11;
//Calculating values for interest Paid, principlePaid and balance remaining.
interest Paid = interest / months
balance;
principalPaid = minimumPaid - interest Paid;
balanceRemaining = balance - principalPaid;
//If minimumPaid is greater than 119 & greater than/equal to 120, output balanceRemaining.
if (minimumPaid > 119 && minimumPaid >= 120) {
System.out.println("Debt amount: $" + balance);
System.out.println("If the minimum payment is: $" + minimumPaid + "0");
System.out.println("Balance remaining after one month: $" + balanceRemaining + "0");
System.out.println();
//Calculating balanceRemaining after 2 months.
for (int i = 0; i < monthsRemaining; ++i) {
balanceRemaining = balanceRemaining minimumPaid + interest Paid;
if (i == 0) {
System.out.printf("Balance after two months: $ %.2f", balanceRemaining);
System.out.println();
}
//Calculating balanceRemaining after 3 months.
if (i == 1) {
System.out.printf("Balance after three months: $%.2f", balanceRemaining);
System.out.println();
}
//Calculating balanceRemaining after 4 months.
if (i == 2) {
System.out.printf("Balance after four months: $%.2f", balanceRemaining);
System.out.println();
}
//Calculating balanceRemaining after 5 months.
if (i == 3) {
System.out.printf("Balance after five months $ %.2f", balanceRemaining);
System.out.println();
}
//Calculating balanceRemaining after 6 months.
if (i == 4) {
System.out.printf("Balance after six months: $%.2f", balanceRemaining);
System.out.println();
}
Transcribed Image Text:public static void main(String[] args) { Scanner scnr = new Scanner(System.in); //Initializing integers and doubles. int months; int balance; double balanceRemaining; double interest; double interest Paid; double principalPaid; double minimumRate; double minimumPaid; int monthsRemaining; int userInput; //Asking for user to input minimumPaid System.out.println("Enter an amount that is not below 120: "); minimumPaid = scnr.nextDouble(); System.out.println(); //If user enters an amount less than 120, they're prompted to reenter a supported amount. if (minimumPaid < 120) { System.out.println("Invalid amount, please re-enter."); minimumPaid = scnr.nextDouble(); } //Initializing values for the following equations. balance 6000; interest = 0.18; minimumRate = 0.02; months = 12; monthsRemaining = 11; //Calculating values for interest Paid, principlePaid and balance remaining. interest Paid = interest / months balance; principalPaid = minimumPaid - interest Paid; balanceRemaining = balance - principalPaid; //If minimumPaid is greater than 119 & greater than/equal to 120, output balanceRemaining. if (minimumPaid > 119 && minimumPaid >= 120) { System.out.println("Debt amount: $" + balance); System.out.println("If the minimum payment is: $" + minimumPaid + "0"); System.out.println("Balance remaining after one month: $" + balanceRemaining + "0"); System.out.println(); //Calculating balanceRemaining after 2 months. for (int i = 0; i < monthsRemaining; ++i) { balanceRemaining = balanceRemaining minimumPaid + interest Paid; if (i == 0) { System.out.printf("Balance after two months: $ %.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 3 months. if (i == 1) { System.out.printf("Balance after three months: $%.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 4 months. if (i == 2) { System.out.printf("Balance after four months: $%.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 5 months. if (i == 3) { System.out.printf("Balance after five months $ %.2f", balanceRemaining); System.out.println(); } //Calculating balanceRemaining after 6 months. if (i == 4) { System.out.printf("Balance after six months: $%.2f", balanceRemaining); System.out.println(); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

How do I output 7 years with the months? I added a month variable, but the rest of the code is still the same. I get 73 years instead of 7. Code below.

 if (minimumPaid > 119 && minimumPaid >= 120) {
      int month = 1;
      int i;

      // Calculating int amount of years it'll take to pay off balanceRemaining.
      for (i = 0; i >= 0; ++i) {
        interestPaid = (interest / months) * balance;
        balance = balance - (int)principalPaid + (int) interestPaid;
        if (balance <= 0) {
          System.out.println("Your debt will be paid off in: " + month / 12 + " years");

          // Output and calculation if amount is paid off in months.
          month = month % 12;
          if (month > 0)
          System.out.println("and " + month + " months.");
          break;
        } else {
          month = month + 1;
        }
      }
    }
    scnr.close();
  }
}

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY