Define a getter for the percent of current balance to pay

Assignment Help JAVA Programming
Reference no: EM131310188

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.

Reference no: EM131310188

Questions Cloud

Create an application that displays payroll information : To create an application that displays PAYROLL information. The application should allow the user to enter the following data for four employees Number of hours worked.
How each feature can be used to monitor employee benefits : Describe the major features of this Website and how each feature can be used to monitor employee benefits. Explain how employers could verify that their employee benefits comply with all federal laws by using this resource
President and congress increased government purchases : Suppose real GDP is currently $12.5 trillion and potential real GDP is $13 trillion. If the president and Congress increased government purchases by $150 billion, what would be the result on the economy if the MPC is .80?
What is the nominal rate of return on these bonds : Wine and Roses, Inc. offers a 6.0 percent coupon bond with semiannual payments and a yield to maturity of 6.48 percent. The bonds mature in 7 years. What is the market price of a $1,000 face value bond? The outstanding bonds of Roy Thomas, Inc. provi..
Define a getter for the percent of current balance to pay : CS210 Introduction to Programming- 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. Define and use three local constants.
How often age discrimination claims are filed : Find and analyze any statistics on how often age discrimination claims are filed. In addition, should the laws be changed to cover age discrimination against people younger than 40 years of age
Describe a reference validation mechanism. : Use the Common Criteria to write security requirements for identifying the security functional and assurance requirements that define a security policy that implements the Bell-LaPadula Model.
What kinds of options is bruce proposing : What kinds of options is Bruce proposing? How much would the options be worth? Would the equity-linked and bear-market deposits generate positive NPV for Gibb River Bank?
How was the team brought back together : Briefly describe a time when you were part of a dysfunctional team. Why was it dysfunctional? Give specific examples. How was the team brought back together

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Write player classes that have certain behaviour

Write player classes that have certain behaviour. These classes will lead you along to implementing the players you will need for the project.

  Write code that prompts the user to enter a string

Write code that prompts the user to enter a string containing ONLY a series of digits, then complete all of the following operations:

  Write a main method that will simulate playing the game

On the Monty Hall game show, a contestant is given a choice of three doors. Behind one door is a car and behind the other two doors are goats.

  The waiting state in java programming

Which is the way in which a thread can enter the waiting state in java programming?

  Write an equivalent section of java code.

What is true after the following statements in a C/C++ program have been executed?

  Constructing a simple flowchart that describes simple logic

Constructing a simple flowchart that describes simple logic flow through a program. Translating the flowchart into pseudo code. Creating a simple module, based on the pseudo code created in step 2, which accepts a parameter and returns a value.

  Describe a multidimensional array

Describe a multidimensional array for a summer camp, the first array would be the number of kids say 30, then it would break them up by ages 6-9 (4 different groups) and lastly by sex m or f.

  Write a program creates circlearray

Write a program creates circleArray, an array composed of 10 Circle objects; it then initializes circle radius with any values (increase every time radius value by 5) and displays all circle object area's And also find total area of the circleArra..

  Simulating the behaviour of a train management system

You will develop the component classes of a program for simulating the behaviour of a train management system - You must implement these classes as if other programmers were, at the same time, implementing the code that instantiates them and calls t..

  Create a screenshot of the execution of the implementation

Create a screenshot of the execution of the implementation of your Java program. Note: Click here if you need a tutorial on taking a screenshot.

  Explain the legal doctrine benefits balancing

Explain the legal doctrine "Benefits Balancing" as it pertains to applying the reasonable standard of care doctrine in the medical fields. Does a defense that the majority of physicians normally do not give a particular diagnostic test in the normal ..

  Write a reference class called ctatrain

writing a reference class that consist of the 2nd and 3rd instance variables below. my class should consist of an array of values in the 2nd instance variable

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd