Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Looping Statements 1.Need for have a Java class as described below. All variables should be declared as private and all methods as

Need help with Looping Statements

1.Need for have 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 declaredpublic

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:Aconstructorthat 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.

Aconstructorthat 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.

Adefault constructorthat does nothing (e.g.; a null constructor).

gettermethods 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 aforloop 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.

2.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.

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

investment balance, and the number of years the investment

has run (round).

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

updates the class variabledefaultRate

5.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 inseconds.

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

Use short-cut operations where ever appropriate.

Compile and execute the program. Check your output!!

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

Unity From Zero To Proficiency Beginner A Step By Step Guide To Coding Your First Game

Authors: Patrick Felicia

1st Edition

1091872023, 978-1091872028

More Books

Students also viewed these Programming questions