JAVA PROGRAMMING Using linked list CSC202 fast food restaura
JAVA PROGRAMMING: Using linked list
CSC202 fast food restaurant may not have great food but it prides itself being faster than its major competitors: CSC201, Nandoos, and Taco Tiger. CSC202 requires between 3 and 9 minutes to fill a customer order. On average, a customer arrives at CSC202 every 6 minutes. The manager would like for you to perform a simulation in order to gather statistics about the amount of time customers have to wait between the time they arrive and the time they get their order. For this assignment, You are required to use a linked list to implement the Queue ADT. In addition, because we just started our business, we assume there is only one person taking orders.
Solution
Code:
CSC202.java
package csc202;
import java.util.Scanner;
public class CSC202 {
static int[] que = new int[10];
public static void main(String []args)
{
// create object
LinkedQueue l = new LinkedQueue();
boolean flage = true;
while(flage)
{
Scanner sc = new Scanner(System.in);
System.out.println(\"1. Get Custemer in queue.\");
System.out.println(\"2. Placed Order.\");
System.out.println(\"3.Store Close For Today.\");
System.out.println(\"\ Enter your choice : \");
int choice = sc.nextInt();
switch(choice)
{
case 1:
l.inqueue((3 + (int)(Math.random()*7)));
break;
case 2:
l.dequeue();
break;
case 3:
flage = false;
break;
default:
System.out.println(\"\ Wrong entry.\ Try again.\ \");
}
}
System.out.println(\"Average wait time = \" + l.total_wait/l.count);
}
}
LinkedQueue.java
package csc202;
public class LinkedQueue {
static int inTime = 0;
static int total_wait = 0;
Node front, rear;
public static int count=0;
// Constructor
public LinkedQueue()
{
front = null;
rear = null;
count = 0;
}
//inqueue operation
public void inqueue(int data)
{
inTime=inTime+6;
Node temp = new Node(data);
if (rear == null)
{
front = temp;
rear = temp;
}
else
{
rear.set_Next(temp);
rear = rear.get_Next();
}
}
//dequeue operation
public void dequeue()
{
if (front==null )
System.out.println(\"Underflow Exception\");
Node p = front;
front = p.get_Next();
if (front == null)
rear = null;
total_wait = inTime +p.get_Data()-6;
count++ ;
}
}
Node.java
package csc202;
public class Node {
int data;
Node next;
// Constructor
Node()
{
data=0;
next=null;
}
// Constructor with data
Node(int d)
{
data=d;
next=null;
}
//set link
public void set_Next(Node temp)
{
next=temp;
}
//set data
public void set_Data(int d)
{
data=d;
}
// get link
public Node get_Next()
{
return next;
}
//get data
public int get_Data()
{
return data;
}
}
Output:
run:
1. Get Custemer in queue.
2. Placed Order.
3.Store Close For Today.
Enter your choice :
1
1. Get Custemer in queue.
2. Placed Order.
3.Store Close For Today.
Enter your choice :
1
1. Get Custemer in queue.
2. Placed Order.
3.Store Close For Today.
Enter your choice :
2
1. Get Custemer in queue.
2. Placed Order.
3.Store Close For Today.
Enter your choice :
3
Average wait time = 5
BUILD SUCCESSFUL (total time: 11 seconds)


