Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a Java class as described below. All variables should be declared as private and all methods as public. Save the class definition in a

  1. Define a Java class as described below. All variables should be declared as private and all methods as public. Save the class definition in a file with an appropriate filename.

Class Name: Invest

Symbolic Constants: MIN_INVEST the minimum amount of initial investment accepted without penalty; this should be initialized to $1500.00

FEE the surcharge subtracted from the initial investment if it is less than the min amount (above); this should be initialized to $100.00

Class variable: defaultRate the default interest rate to be used if the user does not specify one; this should be initialized to 5%. This variable should be declared public

Instance Variables: intRate double (the interest rate as a % value)

(Fields) investAmount double (the initial invested amount)

investBalance double (the current value of the investment)

Instance Methods: A constructor that accepts one argument representing the initial invested amount to be assigned to the investAmount field.

The investBalance is determined as follows:

If the initial investment is less than the MIN_INVEST the FEE is deducted

otherwise the value in this field is the same as the input value.

The intRate field is set to the value of the default interest rate class variable.

A constructor that accepts two arguments, an interest rate and an initial invested amount that are assigned to their respective class fields. The investment balance is to be determined as above.

A default constructor that does nothing (e.g.; a null constructor).

getter methods for each of the class fields.

calcEarnings() A method to calculate the interest earnings for one year, where the interest is compounded monthly. To calculate one months interest:

interest = (investBalance * intRate /100) / 12

Use a for loop structure to calculate the total interest amount for a full year. You will need to have an accumulator to total the interest amount. This method should update the invested balance and return the amount earned for the year.

  1. Then, have a class, TestInvest, that contains a main() and subfunctions to test and the above class as indicated below. Save the class in a file with an appropriate file name.

  • Determine the start time for your program.

  • Inside a loop, display a menu with the following options:
  1. New Investment Input the number of years to be calculated. Then call a

method to get the inputs for the class instance (invested

amount, and interest rate (optional ask user)). Instantiate

an instance of the Invest class by calling the appropriate

constructor. The method should then return a reference to

an Invest object.

  1. Calculate Earnings Call a method that calculates the total yearly interest

amount and displays the result and the current balance in

the account for each of the indicated years. Number of

years and an Invest object are input arguments to the class

method. Design a readable display for your output (and

round to the nearest cent).

NOTE: This method should not be allowed to be called more

than once for a particular object.

  1. Summary Report Displays the interest rate, initial deposit amount, final

investment balance, and the number of years the investment

has run (round).

  1. Change Int. Rate Prompts the user to enter a new default interest rate and

updates the class variable defaultRate

  1. Quit Gracefully exits loop.

NOTE: Check that an instance of the Invest class has been created before options 2 or 3 may be processed (e.g.; option 1 has been selected first)

  • Determine the stop time for your program and display the duration the program in seconds.

NOTE: Each menu option should be implemented in a separate class method.

Use short-cut operations where ever appropriate.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

6. Effectively perform the managers role in career management.

Answered: 1 week ago