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();
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c870776-4927-4fbd-b218-f5b27740c439%2Fa13de664-7425-457f-b207-667593fe1029%2Fn2m0u2_processed.png&w=3840&q=75)
![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();
}](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c870776-4927-4fbd-b218-f5b27740c439%2Fa13de664-7425-457f-b207-667593fe1029%2Fasz2dp5_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
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();
}
}
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)