Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Lab4 {
- public static void main (String[] args)
- {
- Staff personnel = new Staff();
- personnel.payWeek();
- }//Main
- }
- abstract class StaffMember {
- protected String name;
- protected String payClass;
- public StaffMember (String eName, String ePayClass)
- {
- name = eName;
- payClass = ePayClass;
- }
- public String toString()
- {
- String result = "Name: " + name + "Class: " + payClass;
- return result;
- }
- public abstract double pay();
- }
- public class Staff {
- private StaffMember[] staffList;
- //Create loop that feeds in user input data
- public Staff ()
- {
- staffList = new StaffMember[5];
- staffList[0] = new Hourly("Anthony","Hourly","16.00");
- staffList[1] = new Employee("Juan","Salary","1600.00");
- staffList[2] = new Hourly("Mana","Hourly","32.00");
- staffList[3] = new Hourly("Felicia","Hourly","16.00");
- staffList[4] = new Hourly("Antonio","Salary","2800.00");
- }
- public void payWeek()
- {
- double amount;
- for (int count=0; count < staffList.length; count++)
- {
- System.out.println (staffList[count]);
- amount = staffList[count].pay();
- if (amount == 0.00)
- System.out.println("Thanks!");
- else
- System.out.println("Paid: " + amount);
- System.out.println("-----------------------------------------------------------");
- }
- }//payWeek
- }
- public class Employee extends StaffMember {
- protected double payRate;
- public Employee (String eName, String ePayClass, double rate)
- {
- super (eName, ePayClass);
- payRate= rate;
- }
- public String toString()
- {
- String result = super.toString();
- result += "Rate: " + payRate;
- return result;
- }
- public double pay()
- {
- return payRate;
- }
- }
- public class Hourly extends Employee {
- private int hoursWorked;
- public Hourly(String eName, String ePayClass, double rate)
- {
- super (eName, ePayClass, rate);
- hoursWorked = 0;
- }
- public void addHours(int moreHours)
- {
- hoursWorked += moreHours;
- }
- public double pay()
- {
- double weeksPaycheck = payRate * hoursWorked;
- hoursWorked = 0;
- return weeksPaycheck;
- }
- public String toString()
- {
- String result = super.toString();
- result += "Hours: "+ hoursWorked + "\t Rate: " +payRate;
- return result;
- }
- }
- //Commissoned employee STILL IN PROGRESS
- public class Commission extends Employee
- {
- Private double percentage;
- public Employee (String eName, String ePayClass, double rate)
- {
- super (eName, ePayClass, payRate);
- percentage = 0;
- }
- //Commissioned Employees get 20% of their sales
- public double getCommission()
- {
- double commission = payRate * 0.20;
- return commission;
- }
- public String toString()
- {
- String result = super.toString();
- result += "\sHours: "+ hours +"\sRate: " + rate;
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement