Write a class named commission with the following features


Lab Assignment: Inheritance and Polymorphism

I. Overriding the equals Method

File Player.java contains a class that holds information about an athlete: name, team, and uniform number.

File ComparePlayers.java contains a skeletal program that uses the Player class to read in information about two baseball players and determine whether or not they are the same player.

1. Fill in the missing code in ComparePlayers so that it reads in two players and prints "Same player" if theyare the same, "Different players" if they are different. Use the equals method, which Player inherits fromthe Object class, to determine whether two players are the same. Are the results what you expect?

2. The problem is that as defined in the Object class, equals does an address comparison. It says thattwo objects are the same if they live at the same memory location, that is, if the variables that holdreferences to them are aliases. The two Player objects in this program are not aliases, so even if theycontain exactly the same information they will be "not equal." To make equals compare the actualinformation in the object, you can override it with a definition specific to the class. It might make sense tosay that two players are "equal" (the same player) if they are on the same team and have the same uniformnumber.

- Use this strategy to define an equals method for the Player class. Your method should take a Playerobject and return true if it is equal to the current object, false otherwise.

- Test your ComparePlayers program using your modified Player class. It should give the results youwould expect.

II. Another Type of Employee

The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and Hourly.java are from Listings 9.1 - 9.7 in the text. The program illustrates inheritance and polymorphism.

In this exercise you will add one more employee type to the class hierarchy (see Figure 9.1 in the text).

The employee will be one that is an hourly employee but also earns a commission on sales. Hence the class,which we'll name Commission, will be derived from the Hourly class.

Write a class named Commission with the following features:

- It extends the Hourly class.

- It has two instance variables (in addition to those inherited): one is the total sales the employee has made(type double) and the second is the commission rate for the employee (the commission rate will be typedouble and will represent the percent (in decimal form) commission the employee earns on sales (so .2would mean the employee earns 20% commission on sales)).

- The constructor takes 6 parameters: the first 5 are the same as for Hourly (name, address, phone number,social security number, hourly pay rate) and the 6th is the commission rate for the employee. Theconstructor should call the constructor of the parent class with the first 5 parameters then use the 6th to setthe commission rate.

- One additional method is needed: public void addSales (double totalSales) that adds the parameter to theinstance variable representing total sales.

- The pay method must call the pay method of the parent class to compute the pay for hours worked then addto that the pay from commission on sales. (See the pay method in the Executive class.) The total salesshould be set back to 0 (note: you don't need to set the hours Worked back to 0-why not?).

- The toStringmethod needs to call the toStringmethod of the parent class then add the total sales to that.

To test your class, update Staff.java as follows:

- Increase the size of the array to 8.

- Add two commissioned employees to the staffList-make up your own names, addresses, phone numbersand social security numbers. Have one of the employees earn $6.25 per hour and 20% commission and theother one earn $9.75 per hour and 15% commission.

- For the first additional employee you added, put the hours worked at 35 and the total sales $400; for thesecond, put the hours at 40 and the sales at $950.

Deliverables

1. Complete all the activities in sectionsI & II in this lab; then zip all your Java SOURCE CODE FILES for submission.

2. Write a lab report in Word or PDF document. The report should be named lab5.docx or lab.pdfand must contain the following:

a. The first page should be a cover page that includes the Class Number, Lab Activity Number, Date, and Instructor's name.

b. A description of the lab activities I & II, the concepts learned and applied. Be sure to elaborate on all the concepts applied. For example, it is not enough to say "I learned and applied Inheritance". You should be able to expand on which part of inheritance you applied, how it works, etc. A minimum of 2-page description is expected.

c. A 1-paragraph conclusion about your experience; how long you spent completing the lab, the challenges you faced.

Attachment:- Lab-Assignment.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a class named commission with the following features
Reference No:- TGS02712285

Now Priced at $45 (50% Discount)

Recommended (93%)

Rated (4.5/5)