In: Computer Science
Convert the attached C++ code to working Java code. Be judicious in the change that you make. This assignment is not about re-writing or improving this code, but rather about recognizing the differences between C++ and Java, and making the necessary coding changes to accommodate how Java does things. PLEASE DO NOT use a built-in Java QUEUE (or any other) container. Additional resources for assignment:
#include <iostream>
#include <string>
using namespace std;
class pizza
{
public:
string ingrediants, address;
pizza *next;
pizza(string ingrediants, string address)
{
this->address = address;
this->ingrediants = ingrediants;
next = NULL;
}
};
void enqueue(pizza **head, pizza **tail, pizza *thispizza)
{
if (*head == NULL) *head = thispizza;
else (*tail)->next = thispizza;
*tail = thispizza;
return;
}
pizza* dequeue(pizza **head, pizza **tail)
{
pizza* pizzatodeliver = NULL;
if (*head != NULL)
{
pizzatodeliver = *head;
*head = (*head)->next;
}
if (*head == NULL) *tail = NULL;
return pizzatodeliver;
}
void deliver(pizza **head, pizza`** tail)
{
pizza *thispizza = dequeue(head, tail);
if (thispizza == NULL)
{
cout << "No deliveries pending" << endl; return;
}
cout << "Deliver a pizza with " << thispizza->ingrediants
<< " to " << thispizza->address << endl;
}
int main()
{
pizza *first = NULL, *last = NULL;
enqueue(&first, &last, new pizza("pepperoni", "1234 Bobcat Trail"));
enqueue(&first, &last, new pizza("sausage", "2345 University Drive"));
deliver(&first, &last);
enqueue(&first, &last, new pizza("extra cheese", "3456 Rickster Road"));
enqueue(&first, &last, new pizza("everything", "4567 King Court"));
enqueue(&first, &last, new pizza("coffee beans", "5678 Java Circle"));
deliver(&first, &last);
deliver(&first, &last);
deliver(&first, &last);
deliver(&first, &last);
deliver(&first, &last);
cin.get();
return 0;
}
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;
}
}
package <missing>;
public class GlobalMembers
{
public static void enqueue(pizza[] head, pizza[] tail,
pizza thispizza)
{
if (head[0] == null)
{
head[0] = thispizza;
}
else
{
tail.next = thispizza;
}
tail[0] = thispizza;
return;
}
public static pizza dequeue(pizza[] head, pizza[] tail)
{
pizza pizzatodeliver = null;
if (head[0] != null)
{
pizzatodeliver = head[0];
head[0] = head.next;
}
if (head[0] == null)
{
tail[0] = null;
}
return pizzatodeliver;
}
public static void deliver(pizza[] head, pizza`[] tail)
{
pizza thispizza = dequeue(head, tail);
if (thispizza == null)
{
System.out.print("No deliveries pending");
System.out.print("\n");
return;
}
System.out.print("Deliver a pizza with ");
System.out.print(thispizza.ingrediants);
System.out.print(" to ");
System.out.print(thispizza.address);
System.out.print("\n");
}
public static int Main()
{
pizza first = null;
pizza last = null;
enqueue(first, last, new pizza("pepperoni", "1234 Bobcat Trail"));
enqueue(first, last, new pizza("sausage", "2345 University Drive"));
deliver(first, last);
enqueue(first, last, new pizza("extra cheese", "3456 Rickster Road"));
enqueue(first, last, new pizza("everything", "4567 King Court"));
enqueue(first, last, new pizza("coffee beans", "5678 Java Circle"));
deliver(first, last);
deliver(first, last);
deliver(first, last);
deliver(first, last);
deliver(first, last);
System.in.read();
return 0;
}
}