Write a class named commission with the given features

Assignment Help JAVA Programming
Reference no: EM131916806

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

Reference no: EM131916806

Questions Cloud

Functional currency under US GAAP is least accurate : Which of the following statements regarding the functional currency under US GAAP is least accurate?
World of smart phone technology : In a world of smart phone technology, we are increasingly tempted to divide our attention.
What motivates issuers to securitize : What motivates issuers to securitize?
Write a health and wellness summary for each individual : Choose 2 of the 5 given profiles and write at least a 525- to 1,050-word Health and Wellness Summary for each individual.
Write a class named commission with the given features : Write a class named Commission with the following features. Complete all the activities in sectionsI & II in this lab.
What is the addition to retained earnings : If the firm paid out $71,000 in cash dividends. What is the addition to retained earnings?
Social visibility and financial cost impact healthcare polic : The question asked in my healthcare policy class is: Discuss how social visibility and financial cost impact healthcare policy.
Understanding caribbean family dynamics : a. Discuss the value (if any) of the book to understanding Caribbean family dynamics.
Examine an aspect of training related to evaluation : Examine an aspect of training related to evaluation, transfer, or ensuring training effectiveness - Imagine that you are planning to propose

Reviews

Write a Review

JAVA Programming Questions & Answers

  Displays the stored array values on the screen

Displays the stored array values on the screen using WriteInt - Prompts the user for integer input a dozen times

  Describe the equivalence classes

Prove that these relations on the set of all functions from Z to Z are equivalence relations. Describe the equivalence classes.

  Make the program especially well structured and readable

Make the program especially well structured and readable. Enhance to functionality of the program in various ways, even small ways.

  The following program will display an integral solution

The following program will display an integral solution to the quadratic equation ax2+bx+c for integral values of a,b, and c, where a,c fall between 0 and 10, while b falls between 1 and 1000.

  Write a program that tests the users ability

CS 1400 - Hilton - Write a program that tests the users ability to memorize a random sequence of colors - you are required to write elegant code

  String as its parameter and returns the length

Write a method named longestWord that accepts a String as its parameter and returns the length of the longest word in the string.A word is a sequence of one or more non-space characters (any character other than the space character).

  The implementation of a password checker

demonstrate knowledge of both exhaustive search of a problem space and lookup search through the implementation of a password checker.

  Artificial intelligence and computational linguistics

Artificial intelligence and computational linguistics - Andy Warhol Paintings - Write your answer to this problem on the next page, and feel free to tear out this page as a reference. Just for fim, here's the output of the method given as input a p..

  Your task in this assignment is to develop a graphical user

your task in this assignment is to develop a graphical user interface based java program that can communicate with a

  Reverses a three digit number producing a result

Hint.First write a static method that reverses a three digit number producing a result as described above, and test it directly from the main method. Your static method should have the following signature.

  Problem regarding the java memory model

Draw a box-and-arrow illustration showing the order constraints on the memory actions (read, load, use, assign,store, write) associated with the four assignments that appear in the two threads (you do not need to show these actions for the two assg..

  Find the errors in the java code

What are the errors in the following codes: What would correct the errors?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd