Hello, I need help for this JAVA homework : Inheritance – Lab You are a programm
ID: 3820972 • Letter: H
Question
Hello, I need help for this JAVA homework :
Inheritance – Lab
You are a programmer in the IT department of an important law firm. Your job is to create a program that will report gross salary amounts and other compensation.
There are three types of employees in your firm:
· Programmers
· Lawyers
· Accountants
Your computer-based solution will use inheritance to reflect the ‘general-to-specific’ nature of your employee hierarchy.
Common attributes for all employees are:
· Name
· Salary
Attributes for specific employee types are:
· Lawyers:
Stock options earned (type int)
· Accountants
Parking allowance amount (type double)
· Programmers:
Bus pass (type boolean)
The three specific classes of employees should extend the abstract Employee class (nobody is a generic employee) and implement their own reportSalary() method.
The pay schedule is:
o Employees earn the base salary of $40K per year
o Accountants earn the base employee salary per year
o Programmers earn the base employee salary plus $20K per year o Lawyers earn the base employee salary plus $30K per year
Requirements:
o Each subclass of Employee must implement its own reportSalary() method. The specific implementations of reportSalary() are limited to a printed line:
System.out.println(“I am a lawyer. I get “ + getSalary() + “, and I have ” + getOptions() + “ shares of stock.”);
System.out.println(“I am an accountant. I make “ + getSalary() + “ plus a parking allowance of “ + getParking());
System.out.println("I am a programmer. I make " + getSalary() + " and I" + ((getBusPass())?" get a bus pass.":" do not get a bus pass."));
o Salaries for specific types of employees are in addition to the base employee salary. Raising the base employee salary should automatically raise salaries for all types of employees (hmmm...).
o An object of the ‘Employee’ class cannot be instantiated because it would be too general.
o Attribute(s) that belong to a super or sub class should be initialized in the corresponding class constructor.
Task 1:
Setup a class hierarchy to accurately reflect the relationships in your law firm.
Task 2:
Create a driver program that will create employee objects and report salaries for your company’s employee base:
Programmers:
Lawyers:
Accountants:
(your name goes here) - Will E. Makit -
Ivana Killmen - Luke N. Dimm - Eileen Dover -
Bill Cheatem - Joe Kisonyou - Seymore Butts -
No bus pass Bus pass
11 shares signing bonus 0 shares signing bonus 100 shares signing bonus
Parking allowance – $ 17.00 Parking allowance – $ 45.50 Parking allowance – $ 2.50
Print your code listing and submit on paper.
Thank you.
Explanation / Answer
Here is your program. In the main method in Employee.java class, change your name in place of "Sal Bans"
Employee.java
package employee;
//Abstract class employee as there will be no direct object of this class
//so there will be no object of this class, thus abstract
public abstract class Employee {
private String name;
private int salary;
private int baseSal = 40;//As this is the base salary, So I have hardcoded in parent class itself. Change here to change salaries for all
public abstract void reportSalary();
//Constructor to set only name specifically for Accountants
public Employee(String nme) {
this.name = nme;
this.salary =baseSal;
}
//Constructor for extra salary addition
public Employee(String nme,int sal) {
this.name = nme;
this.salary =sal+baseSal;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public static void main(String[] args) {
System.out.println("Below are salary details of all employees.");
Employee progA = new Programmers(false, "Sal Bans");
System.out.println(progA.getName()+":");
progA.reportSalary();
Employee progB = new Programmers(true, "Will E. Makit");
System.out.println(progB.getName()+":");
progB.reportSalary();
Employee lawrA = new Lawyers(11, "Ivana Killmen");
System.out.println(lawrA.getName()+":");
lawrA.reportSalary();
Employee lawrB = new Lawyers(0, "Luke N. Dimm");
System.out.println(lawrB.getName()+":");
lawrB.reportSalary();
Employee lawrC = new Lawyers(100, "Eileen Dover");
System.out.println(lawrC.getName()+":");
lawrC.reportSalary();
Employee accA = new Accountants(17.00, "Bill Cheatem");
System.out.println(accA.getName()+":");
accA.reportSalary();
Employee accB = new Accountants(45.50, "Joe Kisonyou");
System.out.println(accB.getName()+":");
accB.reportSalary();
Employee accC = new Accountants(2.50, "Seymore Butts");
System.out.println(accC.getName()+":");
accC.reportSalary();
}
}
Programmers.java
package employee;
public class Programmers extends Employee{
private boolean busPass;
public Programmers(boolean busPass,String name) {
super(name,20);//Constructor of parent class called to set name and update salary
this.busPass = busPass;
}
public boolean isBusPass() {
return busPass;
}
public void setBusPass(boolean busPass) {
this.busPass = busPass;
}
@Override
public void reportSalary() {
System.out.println("I am a programmer. I make $ " + getSalary() + "K and I" + ((isBusPass())?" get a bus pass.":" do not get a bus pass."));
}
}
Lawyers.java
package employee;
public class Lawyers extends Employee {
private int stockOptions;
public Lawyers(int stocks,String name) {
super(name,30);//Constructor of parent class called to set name and update salary
this.stockOptions = stocks;
}
public int getStockOptions() {
return stockOptions;
}
public void setStockOptions(int stockOptions) {
this.stockOptions = stockOptions;
}
@Override
public void reportSalary() {
System.out.println("I am a lawyer. I get $ " + getSalary() + "K, and I have " + getStockOptions() + " shares of stock.");
}
}
Accountants.java
package employee;
public class Accountants extends Employee {
private double parkingAmount;
public Accountants(double parkAmt,String name) {
super(name);
this.parkingAmount = parkAmt;
}
public double getParkingAmount() {
return parkingAmount;
}
public void setParkingAmount(double parkingAmount) {
this.parkingAmount = parkingAmount;
}
@Override
public void reportSalary() {
System.out.println("I am an accountant. I make $ " + getSalary() + "K plus a parking allowance of $ " + getParkingAmount());
}
}
Sample Output:
Below are salary details of all employees.
Sal Bans:
I am a programmer. I make $ 60K and I do not get a bus pass.
Will E. Makit:
I am a programmer. I make $ 60K and I get a bus pass.
Ivana Killmen:
I am a lawyer. I get $ 70K, and I have 11 shares of stock.
Luke N. Dimm:
I am a lawyer. I get $ 70K, and I have 0 shares of stock.
Eileen Dover:
I am a lawyer. I get $ 70K, and I have 100 shares of stock.
Bill Cheatem:
I am an accountant. I make $ 40K plus a parking allowance of $ 17.0
Joe Kisonyou:
I am an accountant. I make $ 40K plus a parking allowance of $ 45.5
Seymore Butts:
I am an accountant. I make $ 40K plus a parking allowance of $ 2.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.