-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.java
More file actions
57 lines (51 loc) · 1.63 KB
/
Driver.java
File metadata and controls
57 lines (51 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Driver {
public static void Main(String[] args) {
Pizza first = null, last = null;
Methods m = new Methods();
m.enqueue(first, last, new Pizza("pepperoni", "1234 Bobcat Trail"));
m.enqueue(first, last, new Pizza("sausage", "2345 University Drive"));
m.deliver(first, last);
m.enqueue(first, last, new Pizza("extra cheese", "3456 Rickster Road"));
m.enqueue(first, last, new Pizza("everything", "4567 King Court"));
m.enqueue(first, last, new Pizza("coffee beans", "5678 Java Circle"));
m.deliver(first, last);
m.deliver(first, last);
m.deliver(first, last);
m.deliver(first, last);
m.deliver(first, last);
}
}
public class Pizza {
String ingredients,address;
Pizza next = new Pizza();
Pizza(String ingredients, String address)
{
this.address = address;
this.ingredients = ingredients;
next = null;
}
public Pizza() {
// TODO Auto-generated constructor stub
}
}
class Methods {
public void enqueue(Pizza head, Pizza tail, Pizza thispizza) {
if (head == null) head = thispizza;
else tail.next = thispizza;
tail = thispizza; return;
}
public Pizza dequeue(Pizza head, Pizza tail) {
Pizza pizzatodeliver = null;
if(head != null)
{pizzatodeliver = head; head = head.next;}
if(head == null) tail = null;
return pizzatodeliver;
}
public void deliver(Pizza head, Pizza tail) {
Pizza thispizza = dequeue(head, tail);
if(thispizza == null)
{System.out.println("No deliveries pending"); return;}
System.out.println("Deliver a pizza with " + thispizza.ingredients
+ " to " + thispizza.address);
}
}