Discount Get CIS 247B ALL WEEKS Solution ONLY $84.70 $112.93
CIS 247B Week 1 - in Java [$8.99]
CIS 247B Week 2 - in Java – Object Construction and Data Abstra... [$15.99]
CIS 247B Week 3 - in Java - Overloaded Methods and Static Methods... [$15.99]
CIS 247B Week 4 - in Java - Composition and Class Interfaces [$15.99]
CIS 247B Week 5 - in Java - Composition, Inheritance, and Polymor... [$15.99]
CIS 247B Week 6 - in Java - Interfaces and Abstract Classes [$19.99]
CIS 247B Week 7 - in Java - Putting It All Together [$19.99]
Get Selected Weeks Solution with ONLY NOT Add Selected Tutorials To Cart
CIS247 CIS 247 CIS/247 - CIS247B - Week 5 - Lab 5 - iLab 5 - in Java - Composition, Inheritance, and Polymorphism - Guaranteed 100% score
    CIS247 CIS 247 CIS/247 - CIS247B - Week 5 - Lab 5 - iLab 5 - in Java - Composition, Inheritance, and Polymorphism - Guaranteed 100% score

CIS247 CIS 247 CIS/247 - CIS247B - Week 5 - Lab 5 - iLab 5 - in Java - Composition, Inheritance, and Polymorphism - Guaranteed 100% score

$15.99

Week 5: Composition, Inheritance, and Polymorphism - iLab

iLab 5 of 7: Inheritance

Submit your assignment to the Dropbox located on the silver tab at the top of this page.
(See Syllabus “Due Dates for Assignments & Exams” for due dates.)
i L A B O V E R V I E W
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.

i L A B S T E P S

STEP 1: Understand the UML Diagram

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.

Employee

#firstName : string

#lastName : string

#gender : char

#dependents : int

#annualSalary : double

#benefit : Benefit

-static numEmployees : int = 0

+Employee()

+Employee(in fname : string, in lname : string, in gen : char, in dep : int, in benefits : Benefit)

+static getNumEmployees() : int

+CalculatePay() : double

+displayEmployee() : void

Benefit

-healthinsurance : string

-lifeinsurance : double

-vacation : int

+Benefit()

+Benefit(in hins : string, in lins : double, in vac : int)

+displayBenefits() : void

Salaried

-MIN_MANAGEMENT_LEVEL : int = 0

-MAX_MANAGEMENT_LEVEL : int = 3

-BONUS_PERCENT : double = 10

-managementLevel : int

+Salaried()

+Salaried(in fname : string, in lname : string, in gen : char, in dep : int, in sal : double, in ben : Benefit, in manLevel : int)

+Salaried(in sal : double, in manLevel : int)

+CalculatePay() : double

+displayEmployee() : void

Hourly

-MIN_WAGE : double = 10

-MAX_WAGE : double = 75

-MIN_HOURS : double = 0

-MAX_HOURS: double = 50

-wage : double

-hours : double

-category : string

+Hourly()

+Hourly(in wage : double, in hours : double, in category : string)

+Hourly(in fname : string, in lname : string, in gen : char, in dep : int, in wage : double, in hours : double, in ben : Benefit, in category : string)

+CalculatePay() : double

+displayEmployee() : void
STEP 2: Create the Project

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

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

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

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

  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

  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

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.

Screenshot of program that reads:

************** Employee Information **************

First Name: George
Last Name: Anderson
Gender: M
Dependents: 5
Annual Salary: $42,000.00
Weekly Pay: $807.69
Health Insurance: Full
Life Insurance: 2000.0
Vacation: 10
Total employees: 1

*************** Employee Information ***************

First Name: Mary
Last Name: Noia
Gender: F
Dependents: 5
Annual Salary: $24,000.00
Weekly Pay: $507.69
Health Insurance: Full
Life Insurance: 1000.0
Vacation: 5
Management Level: 1
Total employees: 2

*************** Employee Information ***************

First Name: Frank
Last Name: Jones
Gender: M Dependents: 3
Annual Salary: $23,400.00
Weekly Pay: $450.00
Health Insurance: None
Life Insurance: 500.0
Vacation: 3
Category: Part-time
Total employees: 3

*************** Revised Employee Information ***************

First Name: Frank
Last Name: Jones
Gender: M
Dependents: 3
Annual Salary: $33,280.00
Weekly Pay: $640.00
Health Insurance: None
Life Insurance: 500.0
Vacation: 3
Category: Part-time
Total employees: 3

STEP 9: Submit Deliverables

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

Submit your lab to the Dropbox located on the silver tab at the top of this page. For instructions on how to use the Dropbox, read these Step-by-Step Instructions or watch this Dropbox Tutorial.
See Syllabus “Due Dates for Assignments & Exams” for due date information.

Solution for CIS247 Week 5 Lab 5 in Java

It is 100% correct solution

How to using solution?

Using any Java IDE (ex Eclipse or Netbean), copy all source codes to src folder, then open and run main class (File BasicUserInterface.Java).

If you have more questions, please contact me via email support@extutorials.com, i will help you any time

Thank you

Attached Files

Move over [ preview ] file name to preview content in it!

  • CIS247B-Week5.zip [476.9KB]
    • Document.docx [324.9KB]
    • Eclipse Project
      • CIS247B_WK5_Lab_LASTNAME
        • .classpath
          • .project
            • bin
            • src
              • Benefit.java [1.1KB] [ preview ]
              • Employee.java [2.7KB] [ preview ]
              • Hourly.java [3.3KB] [ preview ]
              • Salaried.java [1.9KB] [ preview ]
        • ScreenShot-CIS247B-Week5.jpg [121.6KB]
        • source code
          • Benefit.java [1.1KB] [ preview ]
          • Employee.java [2.7KB] [ preview ]
          • Hourly.java [3.3KB] [ preview ]
          • Salaried.java [1.9KB] [ preview ]

      Write a review

      Your Name:


      Your Review: Note: HTML is not translated!

      Rating: Bad           Good

      Enter the code in the box below:



      PURCHASE SAVE
      2 Tutorials 10%
      3 Tutorials 13%
      4 Tutorials 16%
      5 Tutorials 19%
      6 Tutorials 22%
      7 Tutorials 25%
      8 Tutorials 28%
      9 Tutorials 31%
      10 Tutorials 34%
      add url more

      9MZQASHWN73B