Last active
August 29, 2015 14:15
-
-
Save nbavafa/79b7c2419d6946552335 to your computer and use it in GitHub Desktop.
Staff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package inheritance; | |
public class Commission extends Hourly{ | |
public double sales; | |
public double commission; | |
public double allSales; | |
public Commission (String eName, String eAddress, String ePhone, | |
String socSecNumber, double rate, double commissionRate) { | |
super (eName, eAddress, ePhone, socSecNumber, rate); | |
commission = commissionRate; | |
} | |
public void addSales (double totalSales) { | |
totalSales +=sales; | |
allSales = totalSales; | |
} | |
public double pay() { | |
double pay = super.pay() + allSales*commission; | |
sales = 0; | |
return pay; | |
} | |
public String toString() { | |
String result = super.toString(); | |
result += "\nCurrent sales: " + allSales; | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package inheritance; | |
//******************************************************************** | |
// Staff.java Author: Lewis/Loftus/Cocking | |
// | |
// Represents the personnel staff of a particular business. | |
//******************************************************************** | |
public class Staff | |
{ | |
private StaffMember[] staffList; | |
//----------------------------------------------------------------- | |
// Sets up the list of staff members. | |
//----------------------------------------------------------------- | |
public Staff () | |
{ | |
staffList = new StaffMember[8]; | |
staffList[0] = new Executive ("Elliot", "123 Main Line", | |
"555-0469", "123-45-6789", 2423.07); | |
staffList[1] = new Employee ("Dr. Kelso", "456 Off Line", | |
"555-0101", "987-65-4321", 1246.15); | |
staffList[2] = new Employee ("Turk", "789 Off Rocker", | |
"555-0000", "010-20-3040", 1169.23); | |
staffList[3] = new Hourly ("Dr. Cox", "678 Fifth Ave.", | |
"555-0690", "958-47-3625", 10.55); | |
staffList[4] = new Volunteer ("J.D.", "987 Suds Blvd.", | |
"555-8374"); | |
staffList[5] = new Volunteer ("Carla", "321 Duds Lane", | |
"555-7282"); | |
staffList[6] = new Commission ("Adam", "456 LayBack Lane", | |
"555-2451", "521-42-4528", 6.25, .2); | |
staffList[7] = new Commission ("Leila", "10 El Campanero", "555-9799", "545-54-1085", 9.75, .15); | |
((Executive)staffList[0]).awardBonus (500.00); | |
((Hourly)staffList[3]).addHours (40); | |
((Commission)staffList[6]).addHours(35); | |
((Commission)staffList[6]).addSales(400); | |
((Commission)staffList[7]).addHours(40); | |
((Commission)staffList[7]).addSales(950); | |
} | |
public static void main (String args[]) { | |
Staff payer = new Staff(); | |
payer.payday(); | |
} | |
//----------------------------------------------------------------- | |
// Pays all staff members. | |
//----------------------------------------------------------------- | |
public void payday () | |
{ | |
double amount; | |
for (int count=0; count < staffList.length; count++) | |
{ | |
System.out.println (staffList[count]); | |
amount = staffList[count].pay(); // polymorphic | |
if (amount == 0.0) | |
System.out.println ("Thanks!"); | |
else | |
System.out.println ("Paid: " + amount); | |
System.out.println ("-----------------------------------"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment