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 this C++ code to Java code this code is to encrypt and decrypt strings of...
Convert this C++ code to Java code this code is to encrypt and decrypt strings of characters using Caesar cipher please attach samples run of the code #include <iostream> #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string> #define MAX_SIZE 200 void encrypt_str(char xyz[], int key); // Function prototype for the function to encrypt the input string. void decrypt_str(char xyz[], int key); // Function prototype for the function to decrypt the encrypted string. using namespace std; int main() { char input_str[MAX_SIZE];...
Please convert This java Code to C# (.cs) Please make sure the code can run and...
Please convert This java Code to C# (.cs) Please make sure the code can run and show the output Thank you! Let me know if you need more information. Intructions For this assignment you will be creating two classes, an interface, and a driver program: Class Calculator will implement the interface CalcOps o As such it will implement hexToDec() - a method to convert from Hexadecimal to Decimal. Class HexCalc will inherit from Calculator. Interface CalcOps will have abstract methods...
I need convert this java code to C language. There is no string can be used...
I need convert this java code to C language. There is no string can be used in C. Thank you! import java.util.Scanner; public class Nthword { public static void main( String args[] ) { String line; int word; Scanner stdin = new Scanner(System.in); while ( stdin.hasNextLine() ) { line = stdin.nextLine(); word = stdin.nextInt(); stdin.nextLine(); // get rid of the newline after the int System.out.println( "Read line: \"" + line + "\", extracting word [" + word + "]" );...
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)  ...
A simple way to write the code to convert millileters to ounces in java
A simple way to write the code to convert millileters to ounces in java
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT