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

If you carry a balance on a credit card, it can be nice to see how long it would

ID: 3744913 • Letter: I

Question

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 en ding 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.

75 24 15 18 06 55 42 46 49 33 83 84 23 89 71 57 48 11 63 87 79 32 41 01 08 58 00 877 75 36 35 69 34 28 49 94 61 48 54 76 14 65 30 86 93 98 96 10 31 59 93 33 79 29 29 00 - st 50 85 26 72 22 77 36 98 64 32 03 77 53 31 11 93 76 61 47 34 23 12 02 94 86 78 71 | 123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Fi La Ac Ba

Explanation / Answer

PaymentCalculator.java

import java.text.NumberFormat;

import java.util.Locale;

import java.util.Scanner;

public class PaymentCalculator {

private double interestPercent = 1.5;

private Locale locale = new Locale("en", "US");

private NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);

public PaymentCalculator()

{

}

public PaymentCalculator(String firstName, String lastName, int account,

double amount, int percentPay) {

this.firstName = firstName;

this.lastName = lastName;

this.account = account;

this.amount = amount;

this.percentPay = percentPay;

}

private String firstName;

private String lastName;

private int account;

private double amount;

private double percentPay;

private void printCharLine(char ch)

{

for(int i = 0; i < 50; i++) {

System.out.print(ch);

}

System.out.println();

}

public void printHeader()

{

System.out.println();

printCharLine('*');

System.out.println("Credit Payment Schedule");

System.out.println("Customer: " + getFirstName() + " " + getLastName());

System.out.println("Account #:" + account);

System.out.println("Balance Due: " + fmt.format(getAmount()));

System.out.println("Percent To Pay: " + getPercentPay());

System.out.println();

printCharLine('-');

System.out.println("Month Interest Payment Balance");

}

public void pritReport()

{

int i = 1;

double payment, interest;

double firstPayment = (getAmount()*interestPercent/100 + getAmount())*getPercentPay()/100;

while(getAmount() > 0) {

interest = getAmount()*interestPercent/100;

setAmount(getAmount() + interest);

if(getAmount() < firstPayment) {

payment = firstPayment;

}

else {

payment = getAmount()*percentPay/100;

}

if(payment > getAmount()) {

payment = getAmount();

}

setAmount(getAmount() - payment);

System.out.printf("%5d %8s %7s %7s ", i, fmt.format(interest), fmt.format(payment), fmt.format(getAmount()));

i++;

}

}

public void printFooter()

{

printCharLine('-');

printCharLine('*');

}

public void getInput()

{

Scanner sc = new Scanner(System.in);

System.out.print("First Name: ");

setFirstName(sc.nextLine());

System.out.print("Last Name: ");

setLastName(sc.nextLine());

System.out.print("Account #: ");

setAccount(sc.nextInt());

System.out.print("Balance Due: ");

setAmount(sc.nextDouble());

System.out.print("Percent To Pay: ");

setPercentPay(sc.nextDouble());

sc.close();

}

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public int getAccount() {

return account;

}

public void setAccount(int account) {

this.account = account;

}

public double getAmount() {

return amount;

}

public void setAmount(double amount) {

this.amount = amount;

}

public double getPercentPay() {

return percentPay;

}

public void setPercentPay(double percentPay) {

this.percentPay = percentPay;

}

}

Controller.java

public class Controller {

public static void main(String[] args)

{

PaymentCalculator pc = new PaymentCalculator();

pc.getInput();

pc.printHeader();

pc.pritReport();

pc.printFooter();

}

}

Sample run

First Name: Vic

Last Name: Allen

Account #: 2222

Balance Due: 500.00

Percent To Pay: 10

**************************************************

Credit Payment Schedule

Customer: Vic Allen

Account #:2222

Balance Due: $500.00

Percent To Pay: 10.0

--------------------------------------------------

Month Interest Payment Balance

1 $7.50 $50.75 $456.75

2 $6.85 $46.36 $417.24

3 $6.26 $42.35 $381.15

4 $5.72 $38.69 $348.18

5 $5.22 $35.34 $318.06

6 $4.77 $32.28 $290.55

7 $4.36 $29.49 $265.42

8 $3.98 $26.94 $242.46

9 $3.64 $24.61 $221.49

10 $3.32 $22.48 $202.33

11 $3.03 $20.54 $184.83

12 $2.77 $18.76 $168.84

13 $2.53 $17.14 $154.23

14 $2.31 $15.65 $140.89

15 $2.11 $14.30 $128.71

16 $1.93 $13.06 $117.57

17 $1.76 $11.93 $107.40

18 $1.61 $10.90 $98.11

19 $1.47 $9.96 $89.63

20 $1.34 $9.10 $81.87

21 $1.23 $8.31 $74.79

22 $1.12 $7.59 $68.32

23 $1.02 $6.93 $62.41

24 $0.94 $6.33 $57.01

25 $0.86 $5.79 $52.08

26 $0.78 $5.29 $47.58

27 $0.71 $48.29 $0.00

--------------------------------------------------

**************************************************

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