In: Computer Science
Java Coding
Part A
Create a class Employee. Employees have a name. Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name;
Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for basic employees this will just be a lot of 0's but make sure to do the math based on what paycheck returns).
Salaried employees are employed either for 10 or 12 months of the year for some salary. Their paycheck is their salary, divided up into two pays a month for however many months they are employed.
Using inheritance, create a class for this type of employee (more will be added in part B). Don't override reportDeposit. Give a parameterized constructor for name and salary that chains back to the parameterized superclass constructor.
In a main, create an array of employees, and set it up with some of each kind, some with different values. (hint: you've got parameterized constructors...) Loop through the list and call reportDeposit for each employee, also find the employee with the highest paycheck.
Part B
Hourly employees have an hourly wage, and a number of hours they are scheduled to work per week,. One paycheck is based on two weeks of work (they are guaranteed to have the same hours for both weeks). They are paid an extra 5% of their hourly rate for each hour over 40 hours per week they are scheduled.
Adjunct employees may teach up to 18 credits, and are paid $827 per credit, with the total spread across 2 paychecks a month for 4 months.
Add classes for these types of employee.
Add two hourly and two adjunct employees to your array in main. You shouldn't have to change anything else in main.
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
import java.util.*;
import java.util.Scanner;
class Employee {
String name;
Employee(String a) {
name = a;
}
double paycheck() {
return 0;
}
void reportDeposit() {
double taxes = 0.17 * paycheck();
System.out.printf("Original amount of paycheck: %.2f\n", paycheck());
System.out.printf("Amount deducted in taxes: %.2f\n", taxes);
System.out.printf("Final amount: %.2f\n", paycheck() - taxes);
}
}
class Salaried extends Employee {
double salary;
Salaried(String name, double s) {
super(name);
salary = s;
}
@Override
double paycheck() {
return salary;
}
}
class Hourly extends Employee {
double wage;
int hours;
Hourly(String name, double w, int h) {
super(name);
wage = w;
hours = h;
}
@Override
double paycheck() {
double pc = 2 * hours * wage;
double bonus = 0;
if (hours > 40) {
bonus = 2 * (hours - 40) * (wage + 0.05 * wage);
}
return pc + bonus;
}
}
class Adjunct extends Employee {
int credits;
Adjunct(String name, int c) {
super(name);
credits = c;
}
@Override
double paycheck() {
return 827 * credits;
}
}
class MyClass {
public static void main(String[] args) {
Employee[] arr = new Employee[4];
arr[0] = new Employee("abc");
arr[1] = new Salaried("xyz", 400);
arr[2] = new Hourly("pqr", 40, 45);
arr[3] = new Adjunct("ijk", 16);
for (int i = 0; i < arr.length; i++) {
arr[i].reportDeposit();
}
}
}