Question

In: Computer Science

4 Implement a Java program that meets the following requirements • You can use the Java...

4 Implement a Java program that meets the following requirements

• You can use the Java standard sequence data structure API types for sets, lists, stack,queue and priority queue as needed. All are available in the java.util package, which you will want to import in your program. 1. Argue in code comments which data structure, stack or queue, you will use to implement this method. Implement a method which creates some String objects as food orders for a small restaurant, and add them to your data structure. Using your data structure standard operations, Process the orders in first come, first served order, printing out the order and a message about fulfilling it.

2. Argue in code comments which data structure, array-based list or linked list based list, you will use to implement this method, for best effectiveness and performance. Implement a method which simulates a short line (between 3 and 8) of people waiting for a movie using a data structure. Represent each guest with a String, have at least one guest cut to the front of the line, at least one guest leave the line, and all guests eventually processed by printing a message about it, using your data structure standard operations.

3. Implement a main method to call the above methods, demonstrating them working with printed output

Solutions

Expert Solution

package lists;
import java.util.*;
public class MainDemo {
   public static void main(String args[])
   {
       Demo d=new Demo();
       d.restaurant();
       d.movie();
   }
  

}
class Demo
{
   Scanner s=new Scanner(System.in);
  
   public void restaurant()
   {
       Queue q=new LinkedList();// queue follows the mechanism of FIFO(first in first out).
       // for implementing orders queue is the best choice.
       System.out.println("Enter how many orders");
       int n=s.nextInt();
      
       System.out.println("Enter list of orders:");
       for(int i=0;i<n;i++)
       {
           String order=s.next();
           q.add(order);
       }
      
       System.out.println("The Processing of orders is:");
       for(int i=0;i<n;i++)
       {
              
               System.out.println(q.remove());
       }
      
      
      
   }
  
   public void movie()
   {
       LinkedList list = new LinkedList();// linked list is best suitable to implement the list rather than array.
       // array require more adjustments than array.
       System.out.println("Enter how many members(3-8)");
       int n=s.nextInt();
      
       System.out.println("Enter names of quests:");
       for(int i=0;i<n;i++)
       {
           String str=s.next();
           list.add(str); // adding element to list
          
       }
      
       System.out.println("The Processing order of quests is:");
       for(int i=0;i<n;i++)
       {
              
               System.out.println(list.get(i)); // processing order
              
       }
      
       list.removeFirst(); // removing first element from list
       System.out.println("The Processing order of quests after removing first is:");
       for(int i=0;i<list.size();i++)
       {
              
               System.out.println(list.get(i));
              
       }
       System.out.println("Enter the position to remove a guest:");
       int pos=s.nextInt();
       list.remove(pos);// removing element form required position.
       System.out.println("The Processing order of quests from the given position is :");
       for(int i=0;i<list.size();i++)
       {
              
               System.out.println(list.get(i));
              
       }
   }
}

output:

Enter how many orders
4
Enter list of orders:
colby
calas
gumbo
bergenost
The Processing of orders is:
colby
calas
gumbo
bergenost
Enter how many members(3-8)
5
Enter names of quests:
vicky
sam
peter
johm
gosling
The Processing order of quests is:
vicky
sam
peter
johm
gosling
The Processing order of quests after removing first is:
sam
peter
johm
gosling
Enter the position to remove a guest:
2
The Processing order of quests from the given position is :
sam
peter
gosling


Related Solutions

XML and JAVA Write a Java program that meets these requirements. It is important you follow...
XML and JAVA Write a Java program that meets these requirements. It is important you follow these requirements closely. • Create a NetBeans project named LastnameAssign1. Change Lastname to your last name. For example, my project would be named NicholsonAssign1. • In the Java file, print a welcome message that includes your full name. • The program should prompt for an XML filename to write to o The filename entered must end with .xml and have at least one letter...
1. Write a Java program from scratch that meets the following requirements: a. The program is...
1. Write a Java program from scratch that meets the following requirements: a. The program is in a file called Duplicates.java that defines a class called Duplicates (upper/lower case matters) b. The program includes a Java method called noDuplicates that takes an array of integers and returns true if all the integers in that array are distinct (i.e., no duplicates). Otherwise it returns false. Make sure the method is public static. example tests: noDuplicates({}) returns true noDuplicates({-1, 1}) returns true...
. Implement a method that meets the following requirements: Computer Language:Java (a) Try to write this...
. Implement a method that meets the following requirements: Computer Language:Java (a) Try to write this method with as few lines of code as you can (b) Sorts a group of three integers, x,y and z, into increasing order (they do not have to be in a sequence). (c) Assume the value in x is less than the value in z. You can also assume there are no duplicates among x, y and z (none of them contain the same...
1. Implement a method that meets the following requirements: (a) Do not reuse any code for...
1. Implement a method that meets the following requirements: (a) Do not reuse any code for the following: i. Try to write this method with as few lines of code as you can ii. Sorts a group of three integers, x,y and z, into decreasing order (they do not have to be in a sequence). iii. Assume the value in x is less than the value in z. You can also assume there are no duplicates among x, y and...
. Implement a method that meets the following requirements: (a) Calls mergesort to sort an array/list...
. Implement a method that meets the following requirements: (a) Calls mergesort to sort an array/list of at least 5 integers (b) Prints the list before and after sorting.
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: ·...
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: · Your C++ source code file. (The file with the .CPP extension).No other files will be accepted. A screenshot of your program running. Program Instructions: Consider the following incomplete C++ program: #include int main() { … } 1. Write a statement that includes the header files fstream, string, and iomanip in this program. 2. Write statements that declare inFile to be an ifstream variable and...
In this Java program you will implement your own doubly linked lists. Implement the following operations...
In this Java program you will implement your own doubly linked lists. Implement the following operations that Java7 LinkedLists have. 1. public DList() This creates the empty list 2. public void addFirst(String element) adds the element to the front of the list 3. public void addLast(String element) adds the element to the end of the list 4. public String getFirst() 5. public String getLast() 6. public String removeLast() removes & returns the last element of the list. 7. public String...
Write a C program that meets the following requirements. Uses a while loop to display the...
Write a C program that meets the following requirements. Uses a while loop to display the first 10 natural numbers (on one row, with a tab separating each number) Uses a while loop to find the sum of the second set of 10 natural numbers. Reads a user entry and displays all the natural numbers up to the user entry (on a column list with a new line separating each number). Finds and displays the sum of all natural numbers...
Using Python, write a program named hw3b.py that meets the following requirements: Welcome the user to...
Using Python, write a program named hw3b.py that meets the following requirements: Welcome the user to Zion's Pizza Restaurant and ask the user how many people are in their dinner group. If the answer is more than eight (8), print a message saying they'll have to wait for a table. Otherwise, report that their table is ready and take their order. Assume the client orders one pizza, and ask what he/she would like on their pizza, include a loop that...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and fill it with the names of various sandwiches. Make an empty list called finished_sandwiches. Loop through the list of sandwich orders and spring a message for each order such as "I am working on your tuna sandwich" As each sandwich is made, move it to the list of finished sandwiches. After all the sandwiches have been made, print a message listing each sandwich that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT