How do I make "your debt will be paid off in x years" output 7 years and x months with the calculations I have? They're correct, but will output 4.17 years instead of 7 like it's supposed to. What am I missing? Program in images below (program in images, instructions below) You made a $6,000 purchase for  used card using your approved credit card. The card comes with an 18% annual interest rate, and 2% minimum monthly payment rate. After one year, how much is the remaining balance?  Following equations 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

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

How do I make "your debt will be paid off in x years" output 7 years and x months with the calculations I have? They're correct, but will output 4.17 years instead of 7 like it's supposed to. What am I missing? Program in images below (program in images, instructions below)

You made a $6,000 purchase for  used card using your approved credit card. The card comes with an 18%
annual interest rate, and 2% minimum monthly payment rate. After one year,
how much is the remaining balance?

 Following equations 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 

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(); }
//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
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
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