import java.util.Scanner; /* LoanRepayment.java ** Java application that, provided as inputs ** A : amount borrowed (in dollars) ** I : annual interest rate (in percent) ** minD : minimum duration (in # of months) ** maxD : maximum duration (in # of months) ** ** produces a table indicating, for each duration in the range ** [minD..maxD], how much the monthly payment must be to pay off ** the loan in that period of time. ** ** Authors: R. McCloskey and < STUDENT's NAME > ** CMPS 134 Fall 2024 Prog. Assg. #2 ** Collaborated with: ..... ** Known Flaws: ... */ public class LoanRepayment { private static Scanner input; // for reading input // input variables // --------------- private static double A; // amount borrowed private static double I; // annual interest rate private static int minD; // minimum # of months to repay loan private static int maxD; // maximum # of months to repay loan public static void main(String[] args) { establishInputs(args); System.out.println(); reportInputs(); System.out.println(); produceTable(); } /* Assigns values to the four (global) input variables. ** If there are command line arguments, they are taken to be those inputs. ** Otherwise, the user enters inputs at the keyboard in response to ** prompts. */ private static void establishInputs(String[] args) { if (args.length == 0) { // There are no command line arguments, so read input from keyboard input = new Scanner(System.in); A = getDouble("Enter amount borrowed:> "); I = getDouble("Enter annual interest rate:> "); minD = getInt("Enter min duration (# months):> "); maxD = getInt("Enter max duration (# months):> "); } else { // The command line arguments are the four inputs A = Double.parseDouble(args[0]); I = Double.parseDouble(args[1]); minD = Integer.parseInt(args[2]); maxD = Integer.parseInt(args[3]); } } /* Displays the input values. */ private static void reportInputs() { System.out.printf("Loan amount: $%-10.2f\n", A); System.out.printf("Annual interest rate: %5.2f%%\n", I); System.out.printf("Minimum duration: %3d months\n", minD); System.out.printf("Maximum duration: %3d months\n", maxD); } private static void produceTable() { // STUB! } /* Prints the given string (intended to be a user prompt) and returns the ** response (interpreted to be of type double) entered at the keyboard. */ private static double getDouble(String prompt) { System.out.print(prompt); return input.nextDouble(); } /* Prints the given string (intended to be a user prompt) and returns ** the response (interpreted to be of type int) entered at the keyboard. */ private static int getInt(String prompt) { System.out.print(prompt); return input.nextInt(); } }