Schedule:
CODE
import java.util.*;
public class Schedule
{
private Waitress[] fullStaff;
private Waitress[] dayStaff;
private Waitress[][] week;
private int[] allTimes;
private int[] dayTimes;
private int numgirls;
public String[] days;
public Schedule(Waitress[] w)
{
for(int i = 0; i<w.length;i++)
{
w[i].reset();
}
int [] llTimes = {1,2,3,4,5,5,6};
allTimes = llTimes;
numgirls = llTimes.length;
Waitress[][] wee= new Waitress[7][w.length];
week = wee;
fullStaff = w;
numgirls = 7;
String[] d = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
days = d;
}
public void doWork()
{
Random r = new Random();
Waitress w = new Waitress();
int w2 = 0;
int[] lltimes = {1,2,3,4,5,5,6};
boolean b = false;
for(int i =0; i <7;i++)
{
dayStaff = new Waitress[0];
dayTimes = lltimes;
for(int k=6;k>=0;k--)
{
if(fullStaff.length>0)
{
w2 = r.nextInt(fullStaff.length);
w = fullStaff[w2];
b = w.addDay(i,dayTimes[k]);
while(!b)
{
fullStaff = remove(w2,fullStaff);
add(w,dayStaff);
w2 = r.nextInt(fullStaff.length);
w = fullStaff[w2];
b=w.addDay(i,dayTimes[k]);
}
fullStaff = remove(w2,fullStaff);
dayStaff = add(w,dayStaff)
}
}
fullStaff = concat(fullStaff, dayStaff);
week[i] = fullStaff;
}
}
public Waitress[] remove(int n, Waitress[] w)
{
Waitress[] w2=new Waitress[0];
if(w.length > 1)
{
w2 = new Waitress[w.length-1];
int x = 0;
for(int i = 0; i<w.length;i++)
{
if(i!=n)
{
w2[x] = w[i];
x++;
}
}
return w2;
}
else{
return new Waitress[0];
}
}
public Waitress[] concat(Waitress[] w, Waitress[] w2)
{
Waitress[] w3 = new Waitress[w.length + w2.length];
for(int i=0; i<w.length;i++)
w3[i] = w[i];
int x = w.length;
for(int i = 0;i<w2.length;i++)
{
w3[x] = w2[i];
x++;
}
w = w3;
return w;
}
public Waitress[] add(Waitress w3, Waitress[] w)
{
Waitress[] w2 = new Waitress[w.length+1];
for(int i = 0; i<w.length;i++)
{
w2[i] = w[i];
}
w2[w.length] = w3;
w = w2;
return w;
}
public void remove(int n, int[] w)
{
int[] w2 = new int[w.length-1];
int x = 0;
for(int i = 0; i<w.length;i++)
{
if(i!=n)
{
w2[x] = w[i];
x++;
}
else n=-999;
}
w= w2;
}
public void show()
{
int d = 0, i = 0;
for(d = 0; d <7;d++)
{
System.out.println("\n\n\n\n" + days[d] + "\n_____");
for(i =0; i < fullStaff.length; i++)
week[d][i].print(d);
}
}
}
Scheduler:
CODE
class Scheduler
{
public static void main(String args[])
{
Waitress[] onfloor = {new Waitress("Sophia","Whitley"),new Waitress("Kimberly","Creel"),new Waitress("Cindy","Suchasuch"),new Waitress("Michelle","Aldred"),new Waitress("K","P"),new Waitress("Lori","Lori"),new Waitress("Angie","Lion"),new Waitress("Natalie","N"),new Waitress("Candice","Grimm"),new Waitress("Lauren","Swazwald"),new Waitress("Crystal","Cummings"),new Waitress("Aubrey","Tammy"),new Waitress("Allison","Newchick")};
Schedule s = new Schedule(onfloor);
s.doWork();
s.show();
}
}
Waitress:
CODE
public class Waitress
{
public int strength;
public boolean isTrain;
public int bathDay;
public double maxHours;
public double hours;
public int workDays;
public int maxDays;
public String firstName;
public String lastName;
public int weekDay;
public int[] schedule;
public Waitress()
{
firstName = "Jane";
lastName = "Doe";
strength=5;
isTrain=true;
bathDay=0;
maxHours=40d;
hours = 0d;
workDays = 0;
maxDays = 5;
weekDay = 0;
int[] s = {0,0,0,0,0,0,0};
schedule = s;
}
public Waitress(String f, String l)
{
firstName = f;
lastName = l;
strength=5;
isTrain=true;
bathDay=0;
maxHours=40d;
hours = 0d;
workDays = 0;
maxDays = 5;
int[] s = {0,0,0,0,0,0,0};
schedule = s;
}
public void reset()
{
bathDay=0;
hours = 0d;
workDays = 0;
}
public boolean addDay(int day, int time)
{
boolean isOK = false;
if(schedule[day] ==0)
{
if(time == 1)
{
if((hours + 11.5d)<=maxHours && (workDays+1) <=maxDays)
{
hours += 11.5d;
workDays +=1;
isOK=true;
}
}
else if(time == 2)
{
if((hours + 11d)<=maxHours && (workDays+1) <=maxDays)
{
hours += 11d;
workDays +=1;
isOK=true;
}
}
else if(time == 3)
{
if((hours + 10d)<=maxHours && (workDays+1) <=maxDays)
{
hours += 10d;
workDays +=1;
isOK=true;
}
}
else if(time == 4)
{
if((hours + 9.5d)<=maxHours && (workDays+1) <=maxDays)
{
hours += 9.5d;
workDays +=1;
isOK=true;
}
}
else if(time == 5)
{
if((hours + 9d)<=maxHours && (workDays+1) <=maxDays)
{
hours += 9d;
workDays +=1;
isOK=true;
}
}
else if(time == 6)
{
if((hours + 8d)<=maxHours && (workDays+1) <=maxDays)
{
hours += 8d;
workDays +=1;
isOK=true;
}
}
if(isOK == true)
schedule[day] = time;
}
return isOK;
}
public boolean bathroom()
{
boolean doBath=false;
if(bathDay==0)
{
bathDay=1;
doBath = true;
}
else if(bathDay==1 && strength<7)
{
bathDay=2;
doBath = true;
}
return doBath;
}
public boolean isTrain()
{
return isTrain;
}
public boolean isManagement()
{
return false;
}
public void print(int day)
{
int time = schedule[day];
String timeString = "";
if(time == 1)
timeString = "4:30";
else if(time==2)
timeString = "5:00";
else if(time==3)
timeString = "6:00";
else if(time==4)
timeString = "6:30";
else if(time==5)
timeString = "7:00";
else if(time == 6)
timeString = "8:00";
else if(time==0)
timeString = "(X)";
String mys = "";
if(day != 6)
mys = firstName + " " + lastName.charAt(0) + ". - " + timeString;
else
mys = firstName + " " + lastName.charAt(0) + ". - " + timeString + " ---- " + workDays + " days, " + hours + " hours";
System.out.println(mys);
}
}
Manager:
CODE
public class Manager extends Waitress
{
public Manager(String f, String l)
{
firstName = f;
lastName = l;
strength=10;
maxHours=70d;
maxDays=7;
}
}
I keep getting a NullPointerException, can you tell me why? or see if you can get it to work.

