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

  Derrick decides to go to europe

Derrick decides to go to Europe, rather than take a summer job. Which of the following would be considered an implicit cost of this decision?

  Create a login form

In this week's lab, we will create a login form, validate a user based on their login name and password, and allow them to access the system or not

  Write a program to guess a word by trying

Write a program to guess a word by trying to guess the individual characters - The word to be guessed shall be provided using the command-line argument

  Method to store the product of the two arrays in third array

Write a method to store the product of the two arrays in the third array

  Write a java program that would simulate a number of cars

Write a JAVA program that would simulate a number of cars' (e.g. 4) speed meter using the concept of Multithreading. A car's speed can be both increased and decreased using specified keys from the keyboard

  Prepare a contact form and validate the data in java

Prepare a contact form and validate the data in JAVA - Validation should confirm that all input meets the requirements

  Java program that computes a ride you took in taxi

Write a java program that computes a ride you took in taxi. The bill computed based on an initial cost plus the taxi charges 0.5 dirham every 0.3 km.

  Program that prints real solutions to the quadratic equation

Write a Java program that prints all real solutions to the quadratic equation ax^2 + bx + c = 0. Read in a, b, c and use the quadratic formula. If the discriminant (b^2 - 4ac) is negative, display a message stating that there are no real solutions..

  Create a class called verify that will be used to validate

Next create a class called Verify that will be used to validate that a number is within a specified range. It should have one constructor that has two int parameters

  Write a while loop that lets the user enter a number

1) Write a while loop that lets the user enter a number. The number should then be multiplied by 10, and stored in a variable called product. The loop should then iterate as long as product contains a value less than 100.

  Prepare an application that creates object of the classes

Write a CarbonFootPrint with only a pure virtual getCarbonFootprint method -  Have each of your classes inherit from the abstract class and implement the getCarbonFootprint method to compute an appropriate carbon footprint for that class.

  Calculate the average

Create, using NetBeans, a complete Java program called CalcAvgDropLowest - Consider importing java.util.Arrays and using the sort method on your array of number

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