Hi guys,
having a small error that I can't seem to fix for the life of me. Been googling around and I understand the error, but not sure how to go about fixing it so to speak.
Any help with my code is greatly appreciated.
Here is the error code:
Exception in thread "main" java.lang.NullPointerException
at enqueue.enqueueMethod(enqueue.java:22)
at enqueue.main(enqueue.java:8)
And here is my code:
having a small error that I can't seem to fix for the life of me. Been googling around and I understand the error, but not sure how to go about fixing it so to speak.
Any help with my code is greatly appreciated.
Here is the error code:
Exception in thread "main" java.lang.NullPointerException
at enqueue.enqueueMethod(enqueue.java:22)
at enqueue.main(enqueue.java:8)
And here is my code:
Code
public class pizza
{
public String ingrediants;
public String address;
public pizza next;
public pizza(String ingrediants, String address)
{
this.address = address;
this.ingrediants = ingrediants;
next = null;
}
}Code
public class enqueue {
public static void main(String[] args)
{
pizza first[] = null;
pizza last[] = null;
enqueueMethod(first, last, new pizza("pepperoni", "1234 Bobcat Trail"));
enqueueMethod(first, last, new pizza("sausage", "2345 University Drive"));
deliverMethod(first, last);
enqueueMethod(first, last, new pizza("extra cheese", "3456 Rickster Road"));
enqueueMethod(first, last, new pizza("everything", "4567 King Court"));
enqueueMethod(first, last, new pizza("coffee beans", "5678 Java Circle"));
deliverMethod(first, last);
deliverMethod(first, last);
deliverMethod(first, last);
deliverMethod(first, last);
deliverMethod(first, last);
}
public static void enqueueMethod(pizza[] head, pizza[] tail, pizza thispizza)
{
if (head[0] == null)
{
head[0] = thispizza;
}
else
{
tail[0].next = thispizza;
}
tail[0] = thispizza;
return;
}
public static pizza dequeueMethod(pizza[] head, pizza[] tail)
{
pizza pizzatodeliver = null;
if (head[0] != null)
{
pizzatodeliver = head[0];
head[0] = head[0].next;
}
if (head[0] == null)
{
tail[0] = null;
}
return pizzatodeliver;
}
public static void deliverMethod(pizza[] head, pizza[] tail)
{
pizza thispizza = dequeueMethod(head, tail);
if (thispizza == null)
{
System.out.println("No deliveries pending");
return;
}
System.out.println("Deliver a pizza with ");
System.out.println(thispizza.ingrediants);
System.out.println(" to ");
System.out.println(thispizza.address);
}
}
