Question

In: Computer Science

Convert the attached C++ code to working Java code. Be judicious in the change that you...

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;

}

Solutions

Expert Solution

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;

   }
}


Related Solutions

Convert the following C++ code into MIPS assembely. For testing I will be change the values...
Convert the following C++ code into MIPS assembely. For testing I will be change the values for q,y,x with few different values. //q -> $s0 //y -> $s1 //x -> $s2 int main(){ int q = 5; int y = 17; int x = 77; if ( q < 10){ cout << "inside if"; } elseif ( x > 0 || y < 10) { cout << "inside elseif"; } else { cout << "inside else"; } }
can you please convert this python code into java? Python code is as shown below: #...
can you please convert this python code into java? Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited):    # if the element at the current position is 0 we have reached our goal    if row[pos] == 0:        possible = True    else:        # make a copy of the visited array        visited = visited[:]        # if the element at the current position has been already visited then...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating...
Plz convert this C++ code into JAVA code thanks #include<iostream> using namespace std; //function for calculating the average sightings from the Total Sightings array float calcAverage(float totalSightings[],int n) {    int i;    float sum=0.0;    for(i=0;i<n;i++)    sum=sum+totalSightings[i];    return sum/n; } int main() {    // n is no. of bird watchers    //flag , flag2 and flag3 are for validating using while loops    int n,i,flag,flag2,flag3;       //ch also helps in validating    char ch;   ...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {...
CONVERT CODE FROM JAVA TO C# PLEASE AND SHOW OUTPUT import java.util.*; public class TestPaperFolds {    public static void main(String[] args)    {        for(int i = 1; i <= 4; i++)               //loop for i = 1 to 4 folds        {            String fold_string = paperFold(i);   //call paperFold to get the String for i folds            System.out.println("For " + i + " folds we get: " + fold_string);        }    }    public static String paperFold(int numOfFolds)  ...
I need an idea of Java code that will convert an integer (1 to 3,999) into...
I need an idea of Java code that will convert an integer (1 to 3,999) into roman numerals using if statements; arrays and loops sadly aren't allowed and that's all I can come up with.
Take the Java program Pretty.java and convert it to the equivalent C program. You can use...
Take the Java program Pretty.java and convert it to the equivalent C program. You can use the file in.txt as sample input for your program. v import java.io.*; import java.util.*; public class Pretty { public static final int LINE_SIZE = 50; public static void main(String[] parms) { String inputLine; int position = 1; Scanner fileIn = new Scanner(System.in); while (fileIn.hasNextLine()) { inputLine = fileIn.nextLine(); if (inputLine.equals("")) { if (position > 1) { System.out.println(); } System.out.println(); position = 1; } else...
Android Studio Code: Provide a working android studio code i.e java and xml code for the...
Android Studio Code: Provide a working android studio code i.e java and xml code for the activity below: Develop an application that is capable to turn pages back and forth. Detailed Instructions: For the main activity, create a layout that represents a fictitious title and author. The activity should include a clickable button on the bottom right that allows you to go forward to the next activity. The next activity will simply be an image above simple text that can...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT