The List of Employee Types Type Weekly Payment Method Cobra Commander 1 Dollar (
ID: 3548377 • Letter: T
Question
The List of Employee Types Type Weekly Payment Method Cobra Commander 1 Dollar (He makes his money by improving the overall value of the company) High Command Base Salary/52 Crimson Guard Base Salary/52 + (# Hours > 40) * 25 Cobra Trooper (# Hours <= 40) * 12 + (# Hours > 40) * 25 Every person has a name, a base salary and number of hours worked in a week. Create an Employee Base class. It should have the following:1. A constructor that accepts weekly hours, name and base salary
2. An accessor method for name, a base salary and number of hours worked in a week.
3. An abstract method for the weekly pay that returns a double. Create a child class for the four employee types. They should each have the following:
1. A method that overrides the weekly pay method with the correct implementation for the amount.
2. A method that overrides the toString method the prints the employee name and the weekly pay.
3.
Create a Class with a main method that prints the employee name and the weekly pay based on the following data.
Use an arraylist of Employees to hold all the different employees.
Also calculate the total payroll for the week. Use a loop!
Employee Type Name Base Salary Hours for the week Cobra Commander Cobra Commander 0 120 High Command Destro 1,200,000 90 High Command Baroness 900,000 85 Crimson Guard Greg 125,000 60 Crimson Guard Marcia 125,000 67 Crimson Guard Peter 120,000 70 Crimson Guard Jan 80,000 40 Cobra Trooper Larry 0 45 Cobra Trooper Curly 0 35 Cobra Trooper Moe 0 50 Cobra Trooper Marvin the Martian 0 33 Cobra Trooper Hawk 0 18 Cobra Trooper Torpedo 0 56 Cobra Trooper Scarlett 0 43 Cobra Trooper Scoop 0 25 As you may have figured out you work for Cobra. They are really big on discipline and documentation.
Make sure you use javadocs and proper naming conventions.
- Javadocs and Naming Conventions (2 points)
- Parent Class 1 point
- Each child class 1 point (4 total)
- Class with Main method 3 points
Create a child class for the four employee types. They should each have the following:
1. A method that overrides the weekly pay method with the correct implementation for the amount.
2. A method that overrides the toString method the prints the employee name and the weekly pay.
3.
Create a Class with a main method that prints the employee name and the weekly pay based on the following data.
Use an arraylist of Employees to hold all the different employees.
Also calculate the total payroll for the week. Use a loop!
Employee Type Name Base Salary Hours for the week Cobra Commander Cobra Commander 0 120 High Command Destro 1,200,000 90 High Command Baroness 900,000 85 Crimson Guard Greg 125,000 60 Crimson Guard Marcia 125,000 67 Crimson Guard Peter 120,000 70 Crimson Guard Jan 80,000 40 Cobra Trooper Larry 0 45 Cobra Trooper Curly 0 35 Cobra Trooper Moe 0 50 Cobra Trooper Marvin the Martian 0 33 Cobra Trooper Hawk 0 18 Cobra Trooper Torpedo 0 56 Cobra Trooper Scarlett 0 43 Cobra Trooper Scoop 0 25 As you may have figured out you work for Cobra. They are really big on discipline and documentation.
Make sure you use javadocs and proper naming conventions.
Type Weekly Payment Method Cobra Commander 1 Dollar (He makes his money by improving the overall value of the company) High Command Base Salary/52 Crimson Guard Base Salary/52 + (# Hours > 40) * 25 Cobra Trooper (# Hours <= 40) * 12 + (# Hours > 40) * 25
Explanation / Answer
Hi,
Please find the Java programs below constructed as requested above
Employee.Java
/**
* Employee class Defines the attributes and member function, calculates the
* weekly pay of different employee type.
*/
public abstract class Employee {
float weekly_hours;
String name;
float base_salary;
/**
* Default Constructor;
*/
public Employee() {
// TODO Auto-generated constructor stub
}
/**
* Set the value for employee attributes.
*
* @param weekly_hours
* @param name
* @param base_salary
*/
public Employee(float weekly_hours, String name, float base_salary) {
this.weekly_hours = weekly_hours;
this.name = name;
this.base_salary = base_salary;
}
/**
* Get weekly hours
*
* @return weekly_hours
*/
public float getWeekly_hours() {
return weekly_hours;
}
/**
* set weekly hours
*
* @param weekly_hours
*/
public void setWeekly_hours(float weekly_hours) {
this.weekly_hours = weekly_hours;
}
/**
* get name
*
* @return name
*/
public String getName() {
return name;
}
/**
* set name
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* get base salary
*
* @return base_salary
*/
public float getBase_salary() {
return base_salary;
}
/**
* set base salary
*
* @param base_salary
*/
public void setBase_salary(float base_salary) {
this.base_salary = base_salary;
}
/**
* Abstract methodcalculateWeeklyPay
*
* @return double
*/
abstract double calculateWeeklyPay();
/**
* return the name, weekly pay.
*/
@Override
public String toString() {
return "Employee Name " + this.getName() + " Weekly Pay "
+ this.calculateWeeklyPay();
}
}
class CobraCommander extends Employee {
/**
* calculateWeeklyPay for CobraCommander
*/
double calculateWeeklyPay() {
return 1d;
}
}
class HighCommand extends Employee {
/**
* calculate weekly pay for High command
*/
double calculateWeeklyPay() {
// Base Salary/52
return this.getBase_salary() / 52;
}
}
class CrimsonGuard extends Employee {
/**
* calculate weekly pay for crimson guard
*/
double calculateWeeklyPay() {
// Base Salary/52 + (# Hours > 40) * 25
if (this.getWeekly_hours() > 40)
return this.getBase_salary() / 52 + (this.getWeekly_hours() - 40)
* 25;
else
return this.getBase_salary() / 52;
}
}
class CobraTrooper extends Employee {
/**
* calculate weekly pay for cobra trooper
*/
double calculateWeeklyPay() {
// (# Hours <= 40) * 12 + (# Hours > 40) * 25
if (this.getWeekly_hours() > 40)
return (this.getWeekly_hours() - 40) * 12;
else
return (40 - this.getWeekly_hours()) * 25;
}
}
CalculatePayroll.Java
import java.util.ArrayList;
import java.util.List;
/**
*
* Set the value for the employees and Calculate weekly pay for each employee
* and weekly payroll.
*
*/
public class CalculatePayroll {
public static void main(String[] args) {
List<Employee> employees = new ArrayList<Employee>();
Employee cobracommander = new CobraCommander();
cobracommander.setName("Cobra Commander");
cobracommander.setBase_salary(0);
cobracommander.setWeekly_hours(120);
System.out.println(cobracommander.toString());
employees.add(cobracommander);
Employee Destro = new HighCommand();
Destro.setName("Destro");
Destro.setBase_salary(1200000);
Destro.setWeekly_hours(90);
System.out.println(Destro.toString());
employees.add(Destro);
Employee Baroness = new HighCommand();
Baroness.setName("Baroness");
Baroness.setBase_salary(900000);
Baroness.setWeekly_hours(85);
System.out.println(Baroness.toString());
employees.add(Baroness);
Employee Greg = new CrimsonGuard();
Greg.setName("Greg");
Greg.setBase_salary(125000);
Greg.setWeekly_hours(60);
System.out.println(Greg.toString());
employees.add(Greg);
Employee Marcia = new CrimsonGuard();
Marcia.setName("Marcia");
Marcia.setBase_salary(125000);
Marcia.setWeekly_hours(67);
System.out.println(Marcia.toString());
employees.add(Marcia);
Employee Peter = new CrimsonGuard();
Peter.setName("Peter");
Peter.setBase_salary(120000);
Peter.setWeekly_hours(70);
System.out.println(Peter.toString());
employees.add(Peter);
Employee Jan = new CrimsonGuard();
Jan.setName("Jan");
Jan.setBase_salary(80000);
Jan.setWeekly_hours(40);
System.out.println(Jan.toString());
employees.add(Jan);
Employee Larry = new CobraTrooper();
Larry.setName("Larry");
Larry.setBase_salary(0);
Larry.setWeekly_hours(45);
System.out.println(Larry.toString());
employees.add(Larry);
Employee Curly = new CobraTrooper();
Curly.setName("Curly");
Curly.setBase_salary(0);
Curly.setWeekly_hours(35);
System.out.println(Curly.toString());
employees.add(Curly);
Employee Moe = new CobraTrooper();
Moe.setName("Moe");
Moe.setBase_salary(0);
Moe.setWeekly_hours(50);
System.out.println(Moe.toString());
employees.add(Moe);
Employee Marvin = new CobraTrooper();
Marvin.setName("Marvin the Martian");
Marvin.setBase_salary(0);
Marvin.setWeekly_hours(33);
System.out.println(Marvin.toString());
employees.add(Marvin);
Employee Hawk = new CobraTrooper();
Hawk.setName("Hawk");
Hawk.setBase_salary(0);
Hawk.setWeekly_hours(18);
System.out.println(Hawk.toString());
employees.add(Hawk);
Employee Torpedo = new CobraTrooper();
Torpedo.setName("Torpedo ");
Torpedo.setBase_salary(0);
Torpedo.setWeekly_hours(56);
System.out.println(Torpedo.toString());
Employee Scarlett = new CobraTrooper();
Scarlett.setName("Scarlett ");
Scarlett.setBase_salary(0);
Scarlett.setWeekly_hours(43);
System.out.println(Scarlett.toString());
Employee Scoop = new CobraTrooper();
Scoop.setName("Scoop ");
Scoop.setBase_salary(0);
Scoop.setWeekly_hours(25);
System.out.println(Scoop.toString());
employees.add(Torpedo);
double payroll = 0;
for (Employee emp : employees) {
payroll = payroll + emp.calculateWeeklyPay();
}
System.out.println("PAYROLL: " + payroll);
}
}
Output:
Employee Name Cobra Commander Weekly Pay 1.0
Employee Name Destro Weekly Pay 23076.923828125
Employee Name Baroness Weekly Pay 17307.69140625
Employee Name Greg Weekly Pay 2903.84619140625
Employee Name Marcia Weekly Pay 3078.84619140625
Employee Name Peter Weekly Pay 3057.6923828125
Employee Name Jan Weekly Pay 1538.4615478515625
Employee Name Larry Weekly Pay 60.0
Employee Name Curly Weekly Pay 125.0
Employee Name Moe Weekly Pay 120.0
Employee Name Marvin the Martian Weekly Pay 175.0
Employee Name Hawk Weekly Pay 550.0
Employee Name Torpedo Weekly Pay 192.0
Employee Name Scarlett Weekly Pay 36.0
Employee Name Scoop Weekly Pay 375.0
PAYROLL: 52186.46154785156
I have included the Javadoc.
Hope it helps.
Thanks,
Sri
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.