1 create classes triangle rectangle shapedemo a triangle class instance variables wi 5346479
1. Create classes: Triangle, Rectangle, ShapeDemo
a. Triangle class
– instance variables: width, height
– instance methods: setWidth(double w), setHeight(double h), double getWidth(), double getHeight() and double getArea()
* A triangle's area is calculated by width*height*0.5
* all variables are private and methods public.
b. Rectangle class
– instance variables: width, height
– instance methods: setWidth(double w), setHeight(double h), double getWidth(), double getHeight() and double getArea()
* A rectangle's area is calculated by width*height
* all variables are private and methods public.
c. ShapeDemo
Create the main method in which you:
– create objects of Triangle and Rectangle that were defined in a and b.
– assign values for these objects using set methods.
– display areas of the objects you created.
2. Create classes: HourlyEmployee and HourlyEmployeeDemo
a. HourlyEmployee
– instance variables: employeeNumber, employeeName, hoursWorked, hourlyRate.
* employeeNumber and employeeName must be declared as String. hoursWorked is int, and hourlyRate is double.
– instance methods: set and get methods for each instance variable
– addtional instance method: calcMonthlyPay() that calculates a monthly payment.
* calcMonthlyPay() method must return an double value. A monthly payment can be calculated as: hoursWorked* hourlyRate
* all variables are private and methods public.
b. HourlyEmployeeDemo.
– Create the main method. You should include the following code block:
HourlyEmployee he1 = new HourlyEmployee(); //create a new HourlyEmployee object
he1.setEmployeeNumber(“000-00-0000”); // enter your student id here.
he1.setEmployeeName(“John Doe”); // enter your name
he1.setHourlyRate(10.25); he1.setHoursWorked(80);
System.out.println(he1.getEmployeeName() + “'s payment for this month is: $” + he1.calcMonthlyPay() );