Assignment 09 20 Points

Assignment 09 20 Points

CSC 125A – Fall 2007

Assignment 09 – 20 points

Part a) – 10 points

Write a superclass Worker and subclasses HourlyWorker and SalariedWorker. Every worker has a name and a salary rate. Implement the classes in the following way:

Class Worker:

Provide a default constructor

Provide a constructor with name and salaryRatePerHour

Provide the methods: getName(), getSalary(), computePay(int hours)

setName(String s) which sets the name with s, and setSalary(double d) which sets salaryRatePerHour with d.

getName() method returns the name

getSalary() method returns the salaryRatePerHour

computePay(int hours) calculates the weekly salary by multiplying the hours by the salaryRatePerHour and returns weekly salary.

Class SalariedWorker

Assuming that it has no constructor, provide two methods: setName(String s) which sets the name with s, and setSalary(double d) which sets salaryRatePerHour with d.

Override the computePay method in the following way: if the salaried worker worked either more than 40 hours or less than 40 hours, he gets paid only for 40 hours and returns the weekly salary.

Provide a toString() method to print the name of the class and the state of the object of the class.

Class HourlyWorker:

Provide a constructor with the inherited instance fields from the Worker class and excessRate.

Override the computePay method in the following way: if the hourly worker worked more than 40 hours, the excess gets paid at the excessRate times the salaryRatePerHour, and returns weekly salary.

Provide a toString() method to print the name of the class and the state of the object of the class.

Write a test program to test all the classes and methods.

Please copy and paste your source code for all the programs, output, into an email to the grader to in the ProgrammingLand.

Part b) – 10 points

In Java, using inheritance,

1)the subclasses can inherit properties from the super class.

2)Also the subclasses can inherit methods from its super class,

3)add new methods,

4)and override the methods in the superclass.

5)Polymorphism allows the methods with the same name and signature of different classes but with different behaviors.

You need to create a super class of your choice in Alice world. You need to add atleast one property added to this super class as well as create two new methods of your choice. Now create a subclass from this super class with one new property added, one new method added. Also create another subclass from this super class, and in this sub class, override one of the methods in the super class. Now add objects of the super class, two sub classes and call all the created methods on the appropriate objects in a new world and display it in your web account.

Please copy and paste the link to the Alice world in an email to the grader to in the ProgrammingLand.

Part b) Option - (10 points)

Implement a super class Person. Make two classes, Student and Instructor that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Write the class definitions, the constructors, and the methods toString for all classes. Supply a test program that tests these classes and methods.

Select, copy and paste the source code for class and Test class, output in your mail in the Programming Land and send it to the grader to in the ProgrammingLand.

To send the grader an email, please click on the mail icon in the enCoreXpress window, click on Compose New Mail, in the MOO mail editor, type Alex_B in the TO input box, after pasting the code, click on Send MOO mail.

Due date for assignment 09: November 02, 2007 before the end of the class.

Extra credit work 09 – 10 bonus points

Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance field, named department of type String. Supply a method toString that prints the manager's name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate toString methods for all classes. Supply a test program that tests these classes and methods.

Copy the source code for all classes, test program, output into an email and send it to me in PL .

To send me an email, please click on the mail icon in the enCoreXpress window, click on Compose New Mail, in the MOO mail editor, type vijay in the TO input box, after pasting the code, click on Send MOO mail.

Due Date: November, 02, 2007 before the end of the class. Any submission of extra credit work after the due date will not be graded. Please note that you should not take any help from anyone to do the extra credit work including the instructor, tutor, grader, friends, seniors, etc.

Good luck!