Java Programming You are a programmer in the IT department of an important law f
ID: 3821709 • Letter: J
Question
Java Programming
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
Explanation / Answer
package myProject;
//Abstract class Employee definition
abstract class Employees
{
//Instance variables
String name;
double baseSalary;
//Constructor
Employees(String name)
{
this.name = name;
baseSalary = 40000;
}//End of constructor
//Returns salary
double getSalary()
{
return baseSalary;
}//End of method
//Abstract method
abstract void reportSalary();
}//End of class
//Class Lawyers inherited from Employee
class Lawyers extends Employees
{
//Instance variable
int StockOptionsEarned;
//Constructor
Lawyers(String name, int stock)
{
super(name);
StockOptionsEarned = stock;
}//End of constructor
//Overrides salary method
double getSalary()
{
return baseSalary + 30000;
}//End of method
//Returns stock options earned
int getOptions()
{
return StockOptionsEarned;
}//End of method
//Overrides abstract method
void reportSalary()
{
System.out.println(name + " I am a lawyer. I get " + getSalary() + ", and I have " + getOptions() + " shares of stock.");
}//End of method
}//End of class
//Class Accounts inherited from Employee
class Accountants extends Employees
{
//Instance variable
double parkingAllowanceAmount;
//Constructor
Accountants(String name, double par)
{
super(name);
parkingAllowanceAmount = par;
}//End of constructor
//Returns parking allowance
double getParking()
{
return parkingAllowanceAmount;
}//End of method
//Overrides abstract method
void reportSalary()
{
System.out.println(name + " I am an accountant. I make " + getSalary() + " plus a parking allowance of " + getParking());
}//End of method
}//End of class
//Class Programmer inherited from Employee
class Programmers extends Employees
{
//Instance variable
boolean busPass;
//Constructor
Programmers(String name, boolean bp)
{
super(name);
busPass = bp;
}//End of constructor
//Overrides salary
double getSalary()
{
return baseSalary + 20000;
}//End of method
//Returns buss pass status
boolean getBusPass()
{
return busPass;
}//End of method
//Overrides abstract method
void reportSalary()
{
System.out.println(name + " I am a programmer. I make " + getSalary() + " and I " + ((getBusPass())? " get a bus pass.":" do not get a bus pass."));
}//End of method
}//End of class
//Driver class
public class Salary
{
//Main method
public static void main(String ss[])
{
//Creates object for programmer
Programmers pr = new Programmers("Pyari", true);
Programmers pr1 = new Programmers("Sasmita", false);
Accountants ac = new Accountants("Mohan", 100.23);
Lawyers la = new Lawyers("Sahu", 54);
pr.reportSalary();
pr1.reportSalary();
ac.reportSalary();
la.reportSalary();
}//End of main method
}//End of class
Output:
Pyari I am a programmer. I make 60000.0 and I get a bus pass.
Sasmita I am a programmer. I make 60000.0 and I do not get a bus pass.
Mohan I am an accountant. I make 40000.0 plus a parking allowance of 100.23
Sahu I am a lawyer. I get 70000.0, and I have 54 shares of stock.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.