Cash-back offer from May 7th to 12th, 2024: Get a flat 10% cash-back credited to your account for a minimum transaction of $50.Post Your Questions Today!

Question DetailsNormal
$ 28.00

CIS 247 iLAB Week 5 | Complete Solution

Question posted by
Online Tutor Profile
request

iLAB OVERVIEW

Scenario and Summary

The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:

  1. Create a class called Salaried that is derived from Employee.
  2. Create a class called Hourly that is also derived from Employee.
  3. Since all classes/objects inherit from java.lang.object class, change the "displayClass" information method to override the java.lang.object "toString" method.
  4. Override necessary method(s) in each of the new subclasses as applicable.

Deliverables

Due this week:

  • Capture the console output window and paste into a Word document.
  • Zip the project folder file.
  • Put the zip file and screenshots (Word document) in the Dropbox.

iLAB STEPS

STEP 1: Understand the UML Diagram

Back to Top

Notice the change in UML diagram. It is common practice to leave out the accessors and mutators (getters and setters) from UML class diagrams, since there can be so many of them. Unless otherwise specified, it is assumed that there is an accessor (getter) and a mutator (setter) for every class attribute.

 

STEP 2: Create the Project

Back to Top

Create a new project and name it CIS247B_WK5_Lab_LASTNAME. Copy all the source files from the Week 4 project into the Week 5 project.

Before you move on to the next step, build and execute the Week 5 project.

STEP 3: Modify the Benefits Class

Back to Top

All classes that are contained in Java's API as well as any external classes that you or I may create are derived from the java.lang.object class. The Object class contains several methods which are inherited by all other Java classes. One of these methods is called toString. The toString method can be overridden by any class and its purpose is to display an object’s current state. This type of functionality should sound familiar to you. After all, your displayBenefits method was designed to print the current state of a Benefit object! In this week's lab, we are going to move the logic contained in displayBenefits to the toString method. Take a look at Java’s description of the toString method contained in the Object class and pay particular attention to its return type before moving on.

  1. Change the displayBenefits method to override the java.lang.object toString method by simply changing its name from displayBenefits to toString.
  2. Ensure the toString method returns a String and does not explicitly display the state information to the console. Remember, toString does not display information but instead it simply returns a string.

STEP 4: Modify the Employee Class

Back to Top

Java provides three explicit access modifiers for attributes and methods. So far, we have dealt with two of them: public and private. This week, we will use a new access modifier: protected. Java states that "The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package." For additional information on the use of protected as an access modifier, review the Controlling Access to Members of a Class tutorial.

  1. Using the updated Employee class diagram, modify attributes to be protected as necessary.
  2. Change the name of the displayEmployee method to "toString" and modify the new toString method to return an Employee's information as a String. This overrides the java.lang.object toString method.
  3. Delete the iEmployee interface class, and remove the reference from the Employee class.

STEP 5: Create the Salaried Class

Back to Top

In this step, it is necessary to implement constant attributes. As the name implies, constants contain values that do not change. In Java, an attribute is made into a constant by adding the keywords "static final" in the declaration. For additional information on the creation and use of constants, review the Understanding Instance and Class Members tutorial.

One other very important concept to review for this step in the lab is the use of the super method. Super is used to access parent-defined attributes and methods within a subclass. A common practice is to use the code super() or super(arg-list) to invoke the constructor in a parent class. For additional information on the use of super in your application and specifically this week’s constructors, review the Using the Keyword super tutorial.

  1. Using the UML Diagrams from Step 1, create the Salaried classes, ensuring to specify that the Salary class inherits from the Employee class.
  2. For each of the constructors listed in the Salaried class, ensure to invoke the appropriate superclass constructor and pass the correct arguments to the superclass constructor. This will initialize the protected attributes and update the numEmployees counter. Don’t forget to initialize the attributes for Salaried as well!
  3. The valid management levels are 0, 1, 2, and 3, and the min and max management level attributes should be implemented as constants. Make sure to enforce this set of valid values in the management level setter.
  4. Override the calculatePay method to add a 10 percent bonus to the annual salary for each of the management levels (i.e., bonus percentage = managementLevel * BONUS_PERCENT). The bonus percentage should be implemented as a constant. Also remember, the value returned from calculatePay should be equal to an employee's weekly pay.
  5. Override the toString method to add the management level to the employee information. Don't forget to call Employee's toString method to capture the state of the inherited Employee attributes!

STEP 6: Create the Hourly Class

Back to Top

  1. Using the UML Diagrams from Step 1, create the Hourly class, ensuring to specify that the Hourly class inherits from the Employee class.
  2. For each of the constructors listed in the Hourly class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.
  3. The valid category types are "temporary", "part time", and "full time". (Hint: The use of String.equalsIgnoreCase may be useful when setting the value of category. Search through Java's API for more details on the use of equalsIgnoreCase.)
  4. The value for hours must be greater than or equal to 0 and less than or equal to 50. The limits should be implemented as constants.
  5. The provided wage must be between 10 and 75 inclusive, and the limits should be implemented as constants.
  6. Make sure to update the value of annualSalary appropriately every time the value of wage or hours changes. Remember, an Hourly employee's annual salary is calculated using the following formula: wage * hours * 52. Therefore, any change to wage or hours will affect the employee's annual salary!
  7. Override the toString method to add the category to the hourly employee information.

STEP 7: Construct the Main Method

Back to Top

  1. Using previous weeks' assignments as an example, create at least one Employee, Hourly, and Salaried employee.
  2. For each object created, write statements to exercise each of the public methods listed in the class diagram.
  3. For each object created, invoke the object's toString method to display the employee's information.
  4. For each object created, display the number of employees created.

STEP 8: Compile and Test

Back to Top

When done, compile and execute your code, and debug any errors until your code is error-free.

Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.

Your output should resemble the following. Make sure to fully exercise all of your new and overridden subclass methods. This could result in output that is lengthier than the example below.

 

Available Answer
$ 28.00

[Solved] CIS 247 iLAB Week 5 | Complete Solution

  • This solution is not purchased yet.
  • Submitted On 08 Aug, 2015 03:29:58
Answer posted by
Online Tutor Profile
solution
This Tutorial is rated A+ p...
Buy now to view the complete solution
Other Similar Questions
User Profile
Exper...

CIS 247 iLAB Week 5 | Complete Solution

This Tutorial is rated A+ previously,if you have any questions regarding this tutorial then you can contact me....

The benefits of buying study notes from CourseMerits

homeworkhelptime
Assurance Of Timely Delivery
We value your patience, and to ensure you always receive your homework help within the promised time, our dedicated team of tutors begins their work as soon as the request arrives.
tutoring
Best Price In The Market
All the services that are available on our page cost only a nominal amount of money. In fact, the prices are lower than the industry standards. You can always expect value for money from us.
tutorsupport
Uninterrupted 24/7 Support
Our customer support wing remains online 24x7 to provide you seamless assistance. Also, when you post a query or a request here, you can expect an immediate response from our side.
closebutton

$ 629.35