Question: Lab Exercise 05.1 Interest Rate PLEASE USE JAVA Compound interest is the way that you can turn a little bit of money into a lot

Lab Exercise 05.1

Interest Rate

PLEASE USE JAVA

Compound interest is the way that you can turn a little bit of money into a lot of money, if you have enough time.

We have seen this calculation in a previous lab. This exercise will rewrite the program but will define a class named interestRate which will contain several separate methods. These methods will be incorporated into the class definition so that they can be tested by a main test program which I have written. The necessary methods will be as follows:

Constructor create an instance of the class and set the values of

value, rate and time.

calculate perform the interest calculation

validate input a double value and check that it is

between an upper and a lower limit.

The method signatures will be as follows:

constructor sets values and validates them by calling validate

pv present value - double

ir interest rate - double

yr period of calculation (years) - double

calculate computes the interest from the

argument values and returns a double.

public double calculate()

The class constructor will call validate before using the input values and validate will return an error value of -1.0 if the values do not pass the test.

validate receives a positive value (double), insures that it is between an upper limit and a lower limit and returns it to the caller as a double. If the input value is outside the specified limits, the returned value will be -1.0.

private double validate( double testValue, double upLim, double loLim)

The test limits for present-value will be 1.00 and 1000.00, the limits for interest rate will be 0.00 and 0.09 (0% to 9%) and the period must be a positive number.

Testing: Main will use a number of different values to test the interest calculation. An object for each set of values to be tested will be instantiated. Main will then call calculate for each object, and display the results.

The following are some suggested values to test.

pv: 1 100 24 1000 55

ir: 9% 6% 5.5% 5% 24%

yr: 10 10 400 24 17

The main that I write and that you must demonstrate runs correctly will be sure to test for illegal values as well (outside the limits, negative etc.)

Files in finished program:

Main.java supplied on blackboard

interestRate.java supplied by you

This is the Main.java

 public class Main { public static void main(String[] args) { Tester t1 = null; t1 = new Tester(1.0, 0.09, 10.0); t1 = new Tester(12, 0.00, -3); t1 = new Tester(100.0, 0.06, 10); t1 = new Tester(24, 0.055, 400); t1 = new Tester(-24, 0.055, 400); t1 = new Tester(1000, 0.05, 24); t1 = new Tester(55, 0.24, 17); } private static class Tester { private Tester(double v, double r, double p) { interestRate test = new interestRate(v, r, p); double amt = test.calculate(); System.out.print("Investing $" + v + " at " + (r*100) + " percent " + " for " + p + " years yields"); if (amt < 0.0) { System.out.println(" Error!"); } else { System.out.println(" $" + amt); } } } }

Lab Exercise 05.2

Personnel files

PLEASE USE JAVA

You will write a class named Person and two subclasses named Student and Employee. Write classes Faculty and Staff as subclasses of Employee. A Person has a name, address, phone number and email address. A student has a class status (freshman, sophomore, junior or senior). An Employee has an office number, salary and date-hired. A Faculty member has office hours and a rank (assistant-professor, associate-professor, full-professor). A Staff has a title (Ex: Director of student services).

Creating a Person requires that you supply

name, address, phone, email

Creating a Student requires that you supply

status, name, address, phone, email

Creating an Employee requires that you supply

office, salary, hireDate

status, name, address, phone, email

Creating a Faculty requires that you supply

hours, rank,

office, salary, hireDate

status, name, address, phone, email

Creating a Staff requires that you supply

title,

office, salary, hireDate

status, name, address, phone, email

Override the toString() method in each class to display the, class name and all attributes.

Testing:

Files:

Main.java supplied on blackboard

Person.java supplied by you

Student.java supplied by you

Employee.java supplied by you

Faculty.java supplied by you

Staff.java supplied by you

This is the Main Java

public class Main { public static void main(String [] args) { System.out.println(" Faculty #1"); Faculty prof = new Faculty("nine to five", "assistent prof", "Bell-533", "not much", "yesterday", "Joe Buzzard-Catcher", "533 Oak street", "(123)456-7890", "buzzardemail.com"); System.out.print(prof.toString()); System.out.println(" Staff #1"); Staff president = new Staff("University President", "Bell-533", "millions & millions", "yesterday", "Bill Important", "101 University Drive", "(890)567-1234", "Billemail.com"); System.out.print(president.toString()); System.out.println(" Student #1"); Student bot = new Student("freshman, on probation", "Todd McTodd", "101 Fraternity Row", "(000)000-0000", "toddemail.com"); System.out.print(bot.toString()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!