Question

In: Computer Science

Required components: A controller class with Java main() method and a PaymentCalculator class to hold the...

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.

Solutions

Expert Solution

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);

}

}


Related Solutions

Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
2-Dimensional Array Operations. Use a Java class with a main method. In this class (after the...
2-Dimensional Array Operations. Use a Java class with a main method. In this class (after the main method), define and implement the following methods: public static void printArray. This method accepts a two-dimensional double array as its argument and prints all the values of the array, separated by a comma, each row in a separate line. public static double getAverage. This method accepts a two-dimensional double array as its argument and returns the average of all the values in the...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method...
IN JAVA: Build a class called ExamPractice from scratch. This class should include a main method that does the following: Prompt the user to enter a number of inches Read the number of inches entered from the console Convert the inches into an equivalent number of miles, yards, feet, and inches. Output the results to the console. For example, if a user entered 100000 inches, the program would output: 100000 inches is equivalent to: Miles: 1 Yards: 1017 Feet: 2...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑...
in netbeans using Java Create a project and a class with a main method, TestCollectors. ☑ Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. ☑ Add a method addToCollection. In this method,...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
Java Programming Part 1 (20%) Implement a class with a main method. Using an enhanced for...
Java Programming Part 1 (20%) Implement a class with a main method. Using an enhanced for loop, display each element of this array: String[] names = {"alice", "bob", "carla", "dennis", "earl", "felicia"}; Part 2 (30%) In a new class, implement two methods that will each calculate and return the average of an array of numeric values passed into it. Constraints: your two methods must have the same name one method should accept an array of ints; the other should accept...
In Java Create a class called "TestZoo" that holds your main method. Write the code in...
In Java Create a class called "TestZoo" that holds your main method. Write the code in main to create a number of instances of the objects. Create a number of animals and assign a cage and a diet to each. Use a string to specify the diet. Create a zoo object and populate it with your animals. Declare the Animal object in zoo as Animal[] animal = new Animal[3] and add the animals into this array. Note that this zoo...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT