Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have unfortunately accumulated an outstanding balance B at the end of the mo

ID: 3879871 • Letter: Y

Question

You have unfortunately accumulated an outstanding balance B at the end of the month and you can only afford to pay up to some amount M every month. If you do not make any more purchases with the credit card, calculate the minimum number of payments needed to eliminate the outstanding balance. It is possible that you cannot pay off the balance in 100 years (1200 payments). Write a Java program to calculate and display the minimum number of payments needed to eliminate an outstanding balance. Input will be three positive real numbers on separate lines. The real numbers have two digits after the decimal point, satisfying R <= 50.00 and B, M <= 50000.00. Error check inputs. The output is an integer value. If the balance cannot be eliminated in at most 1200 payments, print Impossible. One user-defined method must be used. Refer to the sample output below.

Sample Run:

Enter the monthly interest rate: 2.00

Enter the outstanding monthly balance: 100.00

Enter the amount you can pay: 4.00

It takes 36 minimum payments to eliminate the balance.

Explanation / Answer

import java.util.Scanner;
public class solution

{
public static void main(String[] args){

       //I am using getPayments() method to get number of payments
       //declaring variables to store user input
       //amountTotal = user's outstanding monthly balance
       //payable = the amount the user can pay
       //interest = rate of interest on amount
      
       double amountTotal,payable,interest;
      
       //declaring payments =no of payments to be done
       int paymentsNo=0;

       //defining scanner object to take input and taking inputs
       Scanner scanner = new Scanner(System.in);
       System.out.print("Enter the monthly interest rate: ");
       interest= scanner.nextDouble();
       System.out.print("Enter the outstanding monthly balance: ");
       amountTotal= scanner.nextDouble();
       System.out.print("Enter the amount you can pay: ");
       payable= scanner.nextDouble();
      
       //getting payments number
       paymentsNo=getPayments(amountTotal,interest,payable);
      
               //printing the number of payments if the balance can be eliminated in 1200 payments,else printing the elimination is impossible
       if(paymentsNo>1200)
       System.out.println("The elimination of balance is impossible.");
       else
       System.out.println("It takes "+paymentsNo+" minimum payments to eliminate the balance.");
}
//method definition
   public static int getPayments(double amount,double interestRate,double payableAmount)
   {
       int payments=0;
      
       //running loop until the amount is cleared or payments number cross 1200
       while(amount>0 && payments<=1200)
       {  
           //the formula is the interest amount is added to the principal amount and the paid payment is deducted from the whole amount
           //now the new amount is outstanding amount
          
           amount=amount+(amount/100)*interestRate-payableAmount;
           //for every payment counting the number
           payments++;
           }
       //returning number of payments
       return payments;
       }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote