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

Java . Implement a method that meets the following requirements: (a) Calls mergesort to sort an...
Java . 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.
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: (a) Has the same requirements as the above...
Implement a method that meets the following requirements: (a) Has the same requirements as the above method, but works with an int array that is sorted in increasing order. Attempt your best complexity (b) In comments above the method, explain what its algorithmic complexity is and why (constant, logarithmic, linear, quadratic...)
. 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.
Implement a method that meets the following requirements: (a) Takes as parameter 1) an int array...
Implement a method that meets the following requirements: (a) Takes as parameter 1) an int array A 2) an int number x to search for (b) determines whether x exists in A, and prints a message indicating the result (c) has the best worst case Big Oh complexity you can manage, using only your own thinking and the materials (the worst case growth rate for the number of items searched should be as low as possible, given that A contains...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT