In: Computer Science
Required components:
A controller class with Java main() method and a PaymentCalculator class to hold the data and methods for the application.
Scenario/Information:
If you carry a balance on a credit card, it can be nice to see how long it would take to payoff the card. For this scenario, you should design a Java application the prints a credit card payment schedule. Inputs for your program should include: Customer’s name (first and last), the account number (as an integer), the current balance (as double) and the percent of the balance that will paid off each month (i.e. 5% as double). Your program should use the Java Scanner class to allow the user to enter the input from the Eclipse console. After receiving the input, print a report to the Eclipse console that includes: a header showing the input information and a table of payments. Sample output is shown in Figure 1.
Assume the following:
At the beginning of every month 1.5% interest is added to the balance.
• The customer payment will be calculated using the monthly balance (including the interest) and the Percent to Pay input.
• The ending balance can be calculated using: beginning balance + interest - payment.
• Assume that when the monthly ending balance is less than the initial monthly payment, the customer can afford to pay off the remainder (plus interest) in the next month.
• You can use the Java NumberFormat class to make values appear as currency when printed.
What to do:
Write a new simple Java program with Eclipse with two classes, a Controller class and a PaymentCalculator class. The Controller should include just a main method. The main method should simply declare a PaymentCalculator object and the call methods from the PaymentCalculator to create the output. The PaymentCalculator class should include field variables for each of the inputs, two constructors (a default no-parameter constructor and a second constructor which allows all input values to be passed in to the object), getters and setters for each field variable, and separate methods that: get the input from the user, print the header of the report, print the data rows of the report, print the footer of the report.
If you have any doubts, please give me comment...
import java.util.Locale;
import java.util.Scanner;
import java.text.NumberFormat;
public class PaymentCalculator {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String firstName, lastName;
int accountNo;
double balanceDue, percentPay;
double interest, payment, balance;
System.out.print("First Name: ");
firstName = scnr.next();
System.out.print("Last Name: ");
lastName = scnr.next();
System.out.print("Account #: ");
accountNo = scnr.nextInt();
System.out.print("Balance Due: ");
balanceDue = scnr.nextDouble();
System.out.print("Percent to Pay: ");
percentPay = scnr.nextDouble();
System.out.println("\n************************************************************");
System.out.println("Credit Payment Schedule");
System.out.println("Customer: " + firstName + " " + lastName);
System.out.println("Account #: " + accountNo);
System.out.printf("Balance Due: %.2f", balanceDue);
System.out.println("\n------------------------------------------------------------");
System.out.printf("%5s %10s %10s %10s\n", "Month", "Interest", "Payment", "Balance");
int month = 1;
balance = balanceDue;
NumberFormat fmt = NumberFormat.getCurrencyInstance(new Locale("en", "US"));
double initialMonthBal = 0.0;
do {
interest = balance * (1.5 / 100);
payment = (balance + interest) * (percentPay / 100);
if (month == 1)
initialMonthBal = payment;
if (balance < initialMonthBal) {
payment = balance + interest;
balance = 0.0;
} else
balance = balance + interest - payment;
System.out.printf("%5d %10s %10s %10s\n", month, fmt.format(interest), fmt.format(payment),
fmt.format(balance));
month++;
} while (balance != 0.0);
}
}