C1S247 Lab 6 in Java – Guaranteed 100% score

Lab Price = $8
Please feel free to send us your queries at: [email protected]
Payment Methods

Add to Cart

Buy Now

View Cart

Problem Statement
Week 6: Interfaces and Abstract Classes – iLab

Print This Page

iLab 6 of 7: Abstract Class and Polymorphism

Connect to the iLab here.

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
We have two separate goals this week:
1. We are going to create an abstract Employee class and an abstract calculatePay method. The abstract Employee class will prevent a programmer from creating an object based on Employee. Only objects based on Salaried and Hourly will be allowed. The abstract calculatePay method in Employee will force the child classes to implement calculatePay.
2. We are going to implement Polymorphism and dynamic binding by creating generalized methods that accept generalized Employee objects to collect input and display information. However, in the main method we will pass derived objects of the Employee class into the methods.
Due this week:
• Capture the console output window and paste it into a Word document.
• Zip the project files.
• 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 in the updated UML diagram that the Employee class is designated as abstract by having the class name Employee italicized. Also, the calculatePay method is italicized, which means that it is an abstract method and needs to be implemented in the derived classes.

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_WK6_Lab_LASTNAME. Copy all the source files from the Week 5 project into the Week 6 project.
Before you move on to the next step, build and execute the Week 6 project.
STEP 3: Modify the Employee Class

1. Make the Employee class abstract.
2. Define calculatePay as an abstract method.
STEP 4: Modify the Hourly Class

Implement the calculatePay method. Since calculatePay is not declared as an abstract method in Employee, all subclasses of Employee must provide an implementation for calculatePay. Unlike the Salaried class, the Hourly class does not currently have an implementation for calculatePay and this will cause an error!
STEP 5: Modify the Main Class – Create Generalized Input Methods

In your Main class, create a method called collectEmployeeInformation that accepts as an argument an Employee object and prompts the user for all the employee attributes, retrieves the attributes, makes any necessary conversions, and then sets the attribute value in the object. Remember you may pass both Salaried and Hourly objects into this method. Therefore it will be necessary to determine which type of object you are deal with, at runtime, using the getClass method. The following is an example of how you might use the getClass method:

if (employee.getClass() == Salaried.class){ // Put code here that is specific to Salaried objects } else { // Put code here that is specific to Hourly objects }
Once you have determined the type of object you are dealing with, you will also need to cast that object to the correct type in order to access its class-specific methods. In order to cast a general Employee object to a Salaried object and access one of its class-specific methods, you would do the following:
We are also going to implement error handing this week using a try/catch block. Specifically, you should wrap the code used to acquire and set the life insurance amount and vacation days in try-catch blocks as shown below. The “try” portion of the code looks for an error. If an error occurs parsing the integer, it jumps down to the “catch” portion of the code and displays the error message. Because badInput is still true, it loops back to the “do” and starts over. Once the integer is parsed correctly, badInput is set to false so it exits the loop and correctly sets the value for vacation.

boolean badInput = true; String strVacation = “”; //Must be initialized vacation = 0; //Must be initialized do { try { strVacation = JOptionPane.showInputDialog(“Vacation: “); vacation = Integer.parseInt(strVacation);//Possible Error badInput = false; } catch (Exception ex) { JOptionPane.showMessageDialog(null,strVacation + ” is not an integer”,”Error”,JOptionPane.PLAIN_MESSAGE); } } while(badInput);
STEP 6: Modify the Main Class – Create a Generalized Output Method

Create a method called displayEmployeeInformation that accepts an Employee object, provides an output header string, and then displays Employee information.
STEP 7: Modify the Main Class – Create a Display Number Employee Method

Create a method called displayNumberOfEmployees to display the number of employee objects.
STEP 8: Modify the Main Method

1. Create an array of employee objects with: Employee employeeList[] = new Employee[2];
2. For the first employeeList index, create a Salaried employee.
3. Call the collectEmployeeInformation method, passing in the Salaried object.
4. Use the displayEmployeeInformation method to display the object’s state.
5. Use the displayNumberEmployees method to display the total number of Employees created. Remember, this includes both Salaried and Hourly employees.
6. For the second employeeList index, create an Hourly employee.
7. Repeat Steps 3-5 for the Hourly object.
8. As an educational exercise, you can try to create an Employee object to verify that an error will occur.
STEP 9: 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.
All of the output values should match last week’s output.
STEP 10: Submit Deliverables

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.

Relevant Material
CIS247 Lab6 Output
CIS247 Lab6 Output
* If you want to purchase multiple products then click on “Buy Now” button which will give you ADD TO CART option.Please note that the payment is done through PayPal.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Payment Details


Lab Price = $8
Please feel free to send us your queries at: [email protected]
Payment Methods

Add to Cart

Buy Now

View Cart

Privacy Policy
We take your privacy seriously and will take all measures to protect your personal information.
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
Refund Policy
Incase you face any issues with the tutorial, please free to contact us on [email protected]
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.

Leave a Reply