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("\n \nFaculty #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("\n \nStaff #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("\n \nStudent #1"); Student bot = new Student("freshman, on probation", "Todd McTodd", "101 Fraternity Row", "(000)000-0000", "toddemail.com"); System.out.print(bot.toString()); } }
class:
public class interestRate{
double pv, ir, yr;
interestRate(double value, double rate, double time){
if(this.validate(value, 1000.00, 1.00) != -1.0 && this.validate(rate, 0.09, 0.00) != -1.0){
pv = value;
ir = rate;
yr = time;
// System.out.println("vlaid");
}
else{
ir = 1.0;
yr = 1.0;
pv = -1.00;
}
}
public double calculate(){
return this.pv * java.lang.Math.pow((1 + this.ir),this.yr);
}
private double validate(double testValue, double upLim, double loLim){
if(testValue <= loLim || testValue >= upLim )
return -1.0;
return 1.0;
}
}
2nd question:
Here status is not passing by the main function as given in the exmple main driver class so i pass it as none in faculty and staff class you may replace it as appropriate
public class Person{
// below is the constructor
protected String name, address, phone, email;
public Person(String name, String address, String phone, String email){
this.name = name;
this.address = address;
this.phone = phone;
this.email = email;
}
public String toString(){
return "Class name: Person, name: "+this.name+", address: "+this.address+", phone: "+this.phone+", email: "+this.email;
}
}
public class Student extends Person{
// class extending person and below is the constructor
protected String status;
Student(String status, String name, String address, String phone, String email){
super(name, address, phone, email);
this.status = status;
}
public String toString(){
return "Class name: Student, status: "+this.status+", name: "+this.name+", address: "+this.address+", phone: "+this.phone+", email: "+this.email;
}
}
public class Employee extends Person{
// class extending person and below is the constructor
protected String office, salary, hireDate, status;
Employee(String office, String salary, String hireDate, String status, String name, String address, String phone, String email){
super(name, address, phone, email);
this.office = office;
this.salary = salary;
this.hireDate = hireDate;
this.status = status;
}
public String toString(){
return "Class name: Employee, office: "+this.office+" salary: "+this.salary+" hireDate: "+this.hireDate+" status: "+this.status+", name: "+this.name+", address: "+this.address+", phone: "+this.phone+" email: "+this.email;
}
}
public class Faculty extends Employee{
// class extending Employee and below is the constructor
protected String hours, rank;
Faculty( String hours, String rank, String office, String salary, String hireDate, String status, String name, String address, String phone, String email){
super(office, salary, hireDate,status, name, address, phone, email);
this.hours = hours;
this.rank = rank;
}
public String toString(){
return "Class name: Faculty, rank: "+this.rank+" hour: "+this.hours+" status: "+this.status+", name: "+this.name+", address: "+this.address+", phone: "+this.phone+", email: "+this.email;
}
}
public class Staff extends Employee{
// class extending Employee and below is the constructor
protected String title;
public Staff(String title, String office, String salary, String hireDate, String status, String name, String address, String phone, String email){
super(office, salary, hireDate,status, name, address, phone, email);
this.title= title;
}
public String toString(){
return "Class name: Staff, title: "+this.title+" office: "+this.office+" salary: "+this.salary+" hireDate: "+this.hireDate+" status: "+this.status+", name: "+this.name+", address: "+this.address+", phone: "+this.phone+", email: "+this.email;
}
}
output:
for any query ask in the comment!
Lab Exercise 05.1 Interest Rate PLEASE USE JAVA Compound interest is the way that you can...
a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff 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). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...
This Exercise contains two classes: ValidateTest and Validate. The Validate class uses try-catch and Regex expressions in methods to test data passed to it from the ValidateTest program. Please watch the related videos listed in Canvas and finish creating the 3 remaining methods in the class. The regular expression you will need for a Phone number is: "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$" and for an SSN: "^\\d{3}[- ]?\\d{2}[- ]?\\d{4}$" This exercise is meant to be done with the video listed in the...
You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...
Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...
In this laboratory, we are going to build a base class and a collection of derived classes. Write the code to implement the class Person. A person has a name, address,telephone number and and E-Mail address. Be sure to include accessor functions to return each of these values. Create a derived class Student which has a class status (freshman, sophomore, junior, or senior). Create a derived class Employee which has the attributes office, salary, and date hired. Now define a...
Concepts Tested in this Program: Class Design Constructors Objects Inheritance Program: Design a class named Person and its two subclasses, Student and Employee. Make Faculty and Staff subclasses of Employee. A Person object has a name, address, phone number, and email address (all Strings). A Student Object has a class status (freshman, sophomore, junior, or senior). Define the status as a final String variable. An Employee Object has an office number, salary (both ints ), and a date hired. Use...
Java: Hello, can someone please find a way to call my arraylist "list" and linkedhashmap called "jobMap" in my main method instead of calling them in the 2 classes? Also, is there a way to avoid the "Suppress Warning" portion in RoundRobin.java? I haven't been able to find a way for some reason. This is a job scheduling program, so the output should give the same values. To run: javac Main.java, java Main 5jobs.txt . txt file will be provided...
java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...
JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization { /* *...
please use java do what u can 1. Modify the Student class presented to you as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to be initially zero. Provide a method called set Test Score that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called get...