Placeholder

COMP 274 Week 2 Lab Inheritance and Polymorphism

$12.00

Description

The objective of this programming assignment is to experience the use of inheritance in Java and to see how polymorphism works with inheritance in Java.
The assignment involves writing three classes, plus a test class. The base class is an employee class which contains a couple of attributes common to all employees and a fundamental method to calculate pay. The two derived classes are a commissioned employee that adds payment of a sales commission as part of the pay calculation, and a union employee which adds overtime payment and union dues as part of the pay calculation. The test program will be structured to include a method which accepts a base class reference and demonstrates polymorphic behavior.
The details of the three classes to be implemented are as follows:
An Employee contains a name, a department where the employee works, and an hourly rate of pay. An explicit value constructor should be provided to set all three values when an Employee object is created. There should be mutator methods to set the values of the department and the pay rate. There should be one accessor method which returns a string containing the name and the department in which the employee works. Finally, there should be a weekly pay method that takes an integer parameter for the number of hours worked and returns the weekly pay. If the number of hours worked is less than 40 hours, the pay is the number of hours times the rate. If the number of hours worked is 40 or more, the pay is 40 times the rate.
The Union Employee inherits from the Employee class. A Union Employee contains a dues variable which holds the amount of dues a Union Employee has withheld from their paycheck each week. An explicit value constructor should be provided to set all three values from the base class along with the dues value. There should be a mutator method provided to set the dues variable. The base class weekly pay method should be overridden because a Union Employee gets 1.5 times the rate for any hours over 40 per week. This method should use the base class method to calculate pay for first 40 hours and then add the overtime amount. Also the weekly pay is reduced by the amount of dues withheld.
The Commission Employee inherits from the Employee class. A Commission Employee contains a commission rate and a sales amount variable which are used as part of the pay calculation. An explicit value constructor should be provided to set all 3 values of the base class along with the commission rate variable. There should be mutator methods for the commission rate and the sales amount. The base class weekly pay method should be overridden because the Commission Employee gets the base employee pay plus the commission rate times the sales amount. This method should use the base class weekly pay method to calculate the hourly part of the pay.
The test program needs to create a Union Employee object and a Commission Employee object. The test program must contain a display method which takes a base class Employee object reference along with the number of hours worked by the employee. The display method should use the base class method to get the employee name and department info and output that information. The display method should also use the base class method to get the weekly pay info for the employee object and display that information. The test program should pass the Union Employee object and the Commission Employee object to the display method along with the number of hours each employee has worked. It should test the payroll calculation for the number of hours worked to be less than 40, 40, and greater than 40 hours for each employee type. The output seen should demonstrate polymorphic behavior, that is the base class Employee reference to a Union Employee object elicits Union Employee pay calculations, and the base class Employee reference to a Commission Employee elicits Commission Employee payroll calculations.
Take screen shots of the output of the program. Paste the screen shots and your source code for all your classes into a Word document.
SCREENSHOTS
SOLUTION
PAYMENT
ENTIRE COURSE
The solution includes a zip file.
Attachments [Move over files to preview content of those files]
COMP274_Lab_2.zip (212.38 KB)
COMP274Lab2_Document.docx
COMP274Lab2_Screenshot.png
java source code
CommissionEmployee.java
Employee.java
TestEmployee.java
UnionEmployee.java
Netbeans project
COMP274Lab2
build
classes
.netbeans_automatic_build
.netbeans_update_resources
CommissionEmployee.class
Employee.class
TestEmployee.class
UnionEmployee.class
build.xml
manifest.mf
nbproject
build-impl.xml
genfiles.properties
private
private.properties
project.properties
project.xml
src
CommissionEmployee.java
Employee.java
TestEmployee.java
UnionEmployee.java
test
Preview CommissionEmployee.java
}
xxxxxx xxxxxx xxxxxxxxxxxxxxxxx() {
xxxxxx xxxxxxxxxxxxxx;
}
public void setCommissionRate(double commissionRate) { this.commissionRate = commissionRate; }
public double getSaleAmount() { return saleAmount; }
public void setSaleAmount(double saleAmount) { this.saleAmount = saleAmount; }
xxxxxx xxxxxx xxxxxxxxx() {
xxxxxx xxxxx.xxxxxxxxx() + xxxxxxxxxxxxxx * xxxxxxxxxx;
}
xxxxxx xxxxxx xxxxxxxx() {
Preview Employee.java
xxxxxxxxxxxxx(xxxxxxxxxx);
xxxxxxxxxxxxx(xxxx);
xxxxxxxxxxxxxx(xxxxx);
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDepartment() { return department; }
xxxxxx xxxx xxxxxxxxxxxxx(xxxxxx xxxxxxxxxx) {
xxxx.xxxxxxxxxx = xxxxxxxxxx;
}
xxxxxx xxxxxx xxxxxxxxxxxxx() {
xxxxxx xxxxxxxxxx;
Preview TestEmployee.java
xxxxxx xxxxxxxxxxxxxx;
xxxxxx xxxxxxxxxx;
xxxxxx xxxx;
xxxxxxxx[] xxxxxxxxx = xxx xxxxxxxx[2];
xxxxxxx xxxxx = xxx xxxxxxx(xxxxxx.xx);
for (int i = 0; i < 2; i++) { switch (i) { case 0: System.out.println("Create a Union Employee object"); break; default: System.out.println("Create a Commission Employee object"); break; } System.out.print("tName: "); if (i == 1) { input.nextLine(); } xxxx = xxxxx.xxxxxxxx(); xxxxxx.xxx.xxxxx("xxxxxxxxxxx: "); xxxxxxxxxx = xxxxx.xxxxxxxx(); Preview UnionEmployee.java xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxx { xxxxxxx xxxxxx xxxx; public UnionEmployee(String name, String department, double rate, int hours, double dues) { super(name, department, rate, hours); setDues(dues); } public double getDues() { return dues; } xxxxxx xxxx xxxxxxx(xxxxxx xxxx) { xxxx.xxxx = xxxx; } Preview CommissionEmployee.java } xxxxxx xxxxxx xxxxxxxxxxxxxxxxx() { xxxxxx xxxxxxxxxxxxxx; } public void setCommissionRate(double commissionRate) { this.commissionRate = commissionRate; } public double getSaleAmount() { return saleAmount; } public void setSaleAmount(double saleAmount) { this.saleAmount = saleAmount; } xxxxxx xxxxxx xxxxxxxxx() { xxxxxx xxxxx.xxxxxxxxx() + xxxxxxxxxxxxxx * xxxxxxxxxx; } xxxxxx xxxxxx xxxxxxxx() { Preview Employee.java xxxxxxxxxxxxx(xxxxxxxxxx); xxxxxxxxxxxxx(xxxx); xxxxxxxxxxxxxx(xxxxx); } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDepartment() { return department; } xxxxxx xxxx xxxxxxxxxxxxx(xxxxxx xxxxxxxxxx) { xxxx.xxxxxxxxxx = xxxxxxxxxx; } xxxxxx xxxxxx xxxxxxxxxxxxx() { xxxxxx xxxxxxxxxx; Preview TestEmployee.java xxxxxx xxxxxxxxxxxxxx; xxxxxx xxxxxxxxxx; xxxxxx xxxx; xxxxxxxx[] xxxxxxxxx = xxx xxxxxxxx[2]; xxxxxxx xxxxx = xxx xxxxxxx(xxxxxx.xx); for (int i = 0; i < 2; i++) { switch (i) { case 0: System.out.println("Create a Union Employee object"); break; default: System.out.println("Create a Commission Employee object"); break; } System.out.print("tName: "); if (i == 1) { input.nextLine(); } xxxx = xxxxx.xxxxxxxx(); xxxxxx.xxx.xxxxx("xxxxxxxxxxx: "); xxxxxxxxxx = xxxxx.xxxxxxxx(); Preview UnionEmployee.java xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxx { xxxxxxx xxxxxx xxxx; public UnionEmployee(String name, String department, double rate, int hours, double dues) { super(name, department, rate, hours); setDues(dues); } public double getDues() { return dues; } xxxxxx xxxx xxxxxxx(xxxxxx xxxx) { xxxx.xxxx = xxxx; } Price: $12 Buy Now Checkout Added to cart Buy More Save More Buy at least TWO items & save up to 30% OFF your ENTIRE order! Rack up instant rebates in your shopping cart. Simply add items to your cart, and see the savings add up. Discounts will automatically be applied on eligible orders. COMP 274 Week 2 Lab Inheritance and Polymorphism – $12.00 COMP 274 Week 3 Lab Java application GUI – $15.00 COMP 274 Week 4 Lab Java Program to Convert Temperature – $15.00 COMP 274 Week 5 Lab Timer and Mouse Events and Java Graphics – $19.00 COMP 274 Week 6 Lab Calendar Program – $19.00 COMP 274 Week 7 Lab Java Doc – $19.00 Add to Cart Checkout Added to cart FLASH SALE $75 $108 Save $30 COMP274 Entire Course Get Entire Course You May Also Like: COMP 274 Entire Course COMP 274 Week 1 Lab COMP 274 Week 3 Lab Java Application GUI COMP 274 Week 4 Lab Java Program to Convert Temperature COMP 274 Week 5 Lab Timer and Mouse Events and Java Graphics COMP 274 Week 6 Lab Calendar Program COMP 274 Week 7 Lab Java Doc

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.