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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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