+1-415-670-9189
info@expertsmind.com
Define a getter for the percent of current balance to pay
Course:- JAVA Programming
Reference No.:- EM131310188




Assignment Help
Expertsmind Rated 4.9 / 5 based on 47215 reviews.
Review Site
Assignment Help >> JAVA Programming

Introduction to Programming

Java Programming Assignment: Objects and Loops

Your previous Alice programs implemented the count (for) and while loops.

This assignment will apply the same concepts to Java, along with a third type of loop, the do-while loop. You will again use an object to store data. Then looping statements will be used to run some of the statements repeatedly.

Problem Summary and Equations

Write a program to compare how long it will take to pay off a credit card balance by paying only the minimum required payment each month, or by paying a larger amount each month. The program will work for any credit card balance of $500 or more.

• The credit card will have an annual interest rate between 3% and 25%.

• Interest will be applied monthly. This means that 1/12th of the annual interest will be added to the current balance each month.

• The user can choose to pay down anywhere from 6% to 33% of the balance every month. The payment made each month will always be at least the minimum required payment, but will never be more than the remaining balance.

Program Requirements

This program will implement a "generic" input reading method called readPercent that can be used to read and validate a percentage is within a specified range. The method will include 3 parameters:

- the lowest percentage allowed
- the highest percentage allowed
- a String description of what percentage is being read from the user

By passing in these values as parameters, you can re-use the method to read any range of percentages needed for any data value.

For example, if you were to call the method to read a mortgage rate, which is a percentage between 3.5% and 20%, the call would be:
double mortgageRate = readPercent(3.5, 20, "annual mortgage rate");

Or to read a down payment percent, which is a percentage between 10% and 30%, the call would be:
double downRate = readPercent(10, 30, "down payment percent");

Required Classes and Methods

Two separate classes will be required for this program.

1. Define a Java class with properties and methods for a Credit Card Account, named:

CreditCardAccount

The class will have the following private properties:

- current balance
- annual interest rate (percentage - e.g. 12.5%)
- percent of current balance to pay each month (e.g. 10%)

Within the CreditCardAccount class you will define methods, as follows:

• Define a constructor, with parameters that pass in the user entered values for only two of the properties, the initial balance and annual interest rate.

o Use the parameters to initialize:

- the current balance property to the initial balance parameter value
- the annual interest rate property to the annual interest rate parameter value

o Initialize the percent to pay off each month to 0.

• Define a second constructor, with parameters that pass in the user entered values for all three of the properties, and use them to initialize the property values.

• Define a getter for the percent of current balance to pay each month.

• Define an instance method to determine and return the minimum required payment for a month:

o Define and use three local constants:

- A low balance minimum payment ($50)
- A high balance percentage (5%)
- A low balance limit ($1000)

o If the current balance is below the low balance limit, then the minimum required payment will be the low balance minimum payment.
o Otherwise, the minimum required payment will be the high balance percentage of the current balance.
o Return the correct minimum required payment

• Define a make payment instance method to record and display a payment for one month (note that there will be no loops in this method). This method will:

o Calculate values and display one line of output, containing the data about one month's payment, as follows:

- Display the current (starting) balance.
- Use the current balance to calculate the interest to be applied for the month, and add that interest to the current balance.
- Display the interest charge and current balance (with interest).
- Using the current balance (with interest), calculate the payment for the month, based on the percent of current balance to pay each month data field.
- Call the instance method to determine the minimum required payment.
- Check to see if the calculated payment is less than the minimum required payment.

o If so, set the calculated payment to the minimum required payment.

- The calculated payment may be higher than the remaining balance. So check to see if the calculated payment is higher than the remaining balance.

o If so, set the calculated payment to the remaining balance.

- Display the calculated payment that will be paid for the month.
- Subtract the calculated payment from the current balance (with interest).
- Display the new current balance (i.e. the ending balance, after the payment has been made).

• Define a payoff instance method to calculate and display information each month until the credit card is paid off. This method will:

o Display a line describing the percent of current balance that will be paid each month

- If the percent is 0, display "minimum payment" instead of a percent.

o Display headers for the results (see sample output below).
o Use a while loop to update and display information about the credit card account every month, as follows:

- Display the month number (starting with month 1, and incrementing by 1 each time the code loops).
- Call the above defined make payment method to update and display the data values for the month.

o Stop looping when the current balance reaches 0.
o Return the number of months needed to pay off the card.

NOTE: When one instance method needs to call another instance method, the second instance method should be called using the this reference to reference the current object.

2. Define a second class containing a main method, and additional methods, to compare paying only the minimum required payment each month with paying a larger amount each month. Name the class:

PayoffComparison

Within the PayoffComparison class:

• Define a static method to prompt for, read, and validate an initial credit card balance. The method will:

o Define and use a constant to hold the lowest initial balance allowed ($500). This constant should be used to specify the lowest value allowed in the prompts, and to test for it within conditions.

o Prompt for and read the initial balance.

o If the user enters an initial balance that is below the lowest initial balance allowed:

- Issue an error message, and loop to re-prompt the user and read another value

o Loop until a valid value is entered.
o Return a valid initial balance.

• Define the generic static readPercent method described at the top of this assignment, to prompt for, read, and validate a percentage. This method will:

o Implement a loop that uses a boolean variable as the condition.
o Prompt for and read a percentage.

- The prompt should use the parameters to specify the percentage being read (description) and the lowest and highest percentage rates allowed.

o If the percent entered is not valid (i.e. not between the lowest and highest rate, inclusive):

- Issue an error message, and loop to re-prompt the user and read another value

o Loop until the percent entered is valid.
o Return a valid percentage.

• Define a static method to prompt for, read, and validate the percentage of the balance to be paid off each month. This method will:

o Define constants to hold the lowest and highest paydown percentages allowed (6 and 33).
o Within a loop, until the user enter a valid choice:

- Let the user choose from a menu of five choices on what minimum payment to make: 1 - 10% of remaining balance each month

2 - 20% of remaining balance each month 3 - 30% of remaining balance each month

4 - Some other percent of the balance each month between 6 and 33

- If the user enters 4, call the generic readPercent method to read the percentage of the balance to be paid off each month, between 6 and 33.

- If the user enters an invalid value, loop to display the menu and read another choice.

o Return a valid percentage of the balance to be paid off each month.

• Define a main method that will:

o Define constants to hold the lowest and highest annual interest rates allowed (3 and 25).
o Display a description of what the program will do to the user.
o Read input from the user as follows:

- Call the static methods to read the initial balance.
- Call the static readPercent method to read the annual interest rate.
- Call the static method to read the percentage of the balance to pay off each month.

o After reading all the input, create two new objects of the CreditCardAccount class

- Create the first object using the first constructor and the first two user input values.
- Create the second object using the second constructor and all the user input values.

NOTE: After creating the objects, the variables used to store the values read from the user should not be used again.

o Display a couple of blank lines after reading all of the user input.
o Call the payoff method with the first object, and store the returned number of months.
o Call the payoff method with the second object, and store the returned number of months.
o Display a statement comparing the number of months required to pay off the credit card with only the minimum monthly payments, vs paying off the credit card with a larger monthly payment (use a getter to get the payoff percentage per month).

(The figures in each column should line up with each other on the right - see Sample Output on next page for example)

3. The program must implement both a while and do-while loop somewhere in the code.

4. The program must follow the CS210 Coding Standards from Content section 6.10. Be sure to include the following comments:

o Comments at the top of each code file describing what the class does

- Include tags with the author's name (i.e. your full name) and the version of the code (e.g. version 1.0, Java Assn 5)

o Comments at the top of each method, describing what the method does

- Include tags with names and descriptions of each parameter and return value.

WARNING: The objects, classes, and methods must be implemented exactly as specified above. If your program produces correct output, but you did not create and use the object as specified, and implement the required classes and methods, you will lose a significant number of points.

Testing

• Run, debug, and test your Java program with different inputs, until you are sure that all control structures within your program work correctly.

• The sample inputs and output can be used as the initial test to test your program. But be sure you thoroughly test it using other values as well.




Put your comment
 
Minimize


Ask Question & Get Answers from Experts
Browse some more (JAVA Programming) Materials
Create a class Hugeinteger which uses 40-element array of digits to store integers as large as 40 digits each. Provide a predicate method isZero. If you feel ambitious, also p
public static Measurable maximum(Measurable[] objects)that returns the object with the largest measure. Use that method to determine the country with the largest area from an
Create a Java application named DistanceCalculator.java to solve the following problem. An application is needed to allow a user to enter two cities and display the distances
100-300 Words. We often are handling the unexpected in life.  Kids and pets can offer many of these unexpected occurrences. Where do you see life's every day exception and how
Write a program that prompts the user to input a decimal number and ouputs the number rounded to the nearest integer.Remember the rules around proper development style and for
Describe one way in which one could apply Java graphics in education. Provide one example of such use to support your response and analyze at least three commands that you w
Create a class called Author is designed as follows: Three private instance variables: name (String), email (String), and gender (char of either ‘m' or ‘f'); One constructor t
You implemented a distributed rental car management system using Java TCP Sockets and object streams. The goal of this project is to use code from your TCP project and creat