Jump to content
xisto Community
Sign in to follow this  
Tsunami

Autoschedule Npe can anyone help me figure out why it is doing this and how to fix it

Recommended Posts

ok, i am making an AutoSchedule Program that will take an array of waitresses and assign them times to come in to work for the week basically at random, however it does take into account the number of days worked that week and the number of hours that week so as to not make one person work every single day. Right now it is just supposed to print it in a default system window with the headings of the day. It prints out the time they come in to work that day(either 4:30, 5:00, 6:00, 6:30,7:00, or 8:00) and prints out (X) if they have the day off. The project consists of 3 self written classes and a main function from which to run it all. The files are Waitress, Manager, Schedule, and Scheduler. Here they are

 

 

Schedule:


{

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 = 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;

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 = w;

int x = w.length;

for(int i = 0;i<w2.length;i++)

{

w3[x] = w2;

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 = w;

 

}

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;

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].print(d);

}

}

 

}

_linenums:0'>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.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 = 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; 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 = w; int x = w.length; for(int i = 0;i<w2.length;i++) { w3[x] = w2; 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 = w; } 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; 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].print(d); } } }


Scheduler:

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:

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:

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.