Java Project
For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes.
Classes needed:
SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way:
public class MySortedList<E extends Comparable<E>>
Queue: Implement a generic queue with an ArrayList as the only instance variable. The constructor will instantiate the list. Include standard enqueue and dequeue methods, as well as isEmpty, getSize, and to String.
Customer: The following information should be included as private variables in the Customer class: customerNumber, storeArrivalTime, and shoppingLength. All variables are of type int. There will be NO mutator (setter) methods. Be sure your class meets these requirements:
The constructor should do the following:
There should be accessor (getter) methods for the following:
Implement the Comparable interface with compareTo based on checkOutArrivalTime.
Cashier: extends your Queue class and includes a finishTime instance variable of type integer. finishTime will be set to 0 in the constructor. Include an accessor for finishTime as well as these methods:
public boolean addcustomer(Customer c) //call enqueue public Customer serveNextcustomer (int simClock)
//if the queue is empty, returns null. Otherwise, dequeues an item, sets the finish time equal to (simulation clock + customer’s checkoutLength) and returns the csutomer.
Data objects needed in the driver program:
Output files needed:
Other:
Simulation procedure:
Sample output files are available on Pilot.
Calculation of whether new customer has arrived (needed for step 4 above):
To write the method for determining if a customer has arrived, first calculate the arrivalProbability for a new customer in any given minute of the simulation (assume each clock tick represents a minute). This can be calculated using the information input from the user regarding length of simulation in hours and number of customers arriving per hour. Once you have the probability per minute, use it as follows:
Generating random integers between two boundaries, inclusive:
randomNum = (int) (lowerBound + Math.random() * (upperBound – lowerBound + 1));
Before writing the simulation portin of this project, it is important that the classes that will be used have been thoroughly tested. I suggest you do this preliminary work, writing driver programs as indicated. These driver programs are for testing only, and should not be part of your finishsed project.
When you come in for help on this project, your instructor or TA may ask to see your test programs, to verify that your classes work correctly.
Additionally, you may want to create a driver program that creates an array of cashiers and a sorted list of Customers. Verify that you are able to add and remove items to both the array and the list.
import java.util.*;
import java.util.LinkedList;
import java.util.Queue;
import java.lang.Comparable;
public static void main(String args[])
{
int openlanes, simlength, totalcustomers;
printf("Enter number of Checkoutlanes:(>1)");
scanf("%d",&openlanes);
printf("Enter length of simulation in minutes:(>=10)");
scanf("%d",&simlength);
printf("Enter number of customers expected to come in store every hour(between 1 and 60)");
scanf("%d",totalcustomers);
}
public class Customer (int totalcustomers,int simlength)
{
Customer CNo;
int arrivalprobability=totalcustomers/60*100;
int randomnumber=(int)(0+Math.random()*(100-0+1);
if randomnumber<arrivalprobability
CNo++;
add(CNo);
int storeArrivalTime=simClock;
int shoppinglength=(int)(5+Math.random()*(45-5+1));
int checkoutArrivalTime=storeArrivalTime+shoppinglength;
}
public class CustomerLinkedList<E extend Comparable>extends Customer <E>>
{
public void add(E newCustomer)
{
int x=newCustomer.checkoutArrivalTime
if(head==null)
head=new Node<E>(x,null);
else
{
if(x.compareTo(head.getData())<=0)
{
head=newNode<E>(x,head);
}
else
{
Node<E>previous=head;
Node<E>current=head.getNext();
while(current!=null&&x.compareTo(current.getData())>0){
previous=current;
current=current.getNext());
}
Node<E>node=new Node<E>(x,current));
previous.setNext(node);
}
}
public class Cashier extends Queue class{
public Customer serveNextCustomer(int simLength)
{
Queue<Integer>Cashier=new LinkedList();
int customerserved=0;
if Cashier.peek()==null
return null;
finishTime=simLength+checkoutLength;
if (Customer.checkOutArrivalTime == simClock))
CustomerList.getNext()=null;
Cashier.add(CustomerList.current);
customerserved++;
try {
PrintStream out = new PrintStream(new FileOutputStream(
"OutFile.txt"));
for (int i = 0; i < size; i++)
out.println("Number of customers who entered the store during the simulation="+totalcustomers);
out.println(" •Number of customers still shopping (not in line)"+Customer.getcounn);
out.println(" •Number of customers waiting in a checkout line but not yet being served")
out.println(" •Number of customers who have been or are currently being served by cashiers"+customersserved);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
Java Project For this assignment, you will write a simulation program to determine the average waiting...
Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...
Queues This programming exercise introduces the Queue data structure. The students must create all the necessary methods for the queue and use the queue in a Java program. Step 1 - Create a new project in Netbeans Use the following naming convention: “Module4_Lastname_Assignment1”. Step 2 - Build a solution You have been asked to create a customer service program for a new phone store that will be opening soon. Since this company anticipates being the agent for a rising new...
Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I have so far just basically adds customers to the queue and prints when they arrive. I am struggling with how to implement a way of keeping track of when a given customer finishes(I will attach what I have so far). I had already created queue and node classes (with headers and cpp files) that I modified in my attempt. I would be very grateful...
Please use JAVA program language Discrete event simulation is to simulate events occurring at discrete time points. Between any two consecutive time points, no event occurs. (a) Write a class Event with two integer instance variable time and type, which represents an event of a specific type occurs at time. Also write the constructor Event(int time, int type), which initializes the attributes using the parameters. In using this class, you can assume the getter and setter methods are available. (b)...
In this assignment, you will write a simulator to determine maximum, minimum and average queue length. Important: You can implement with the linked list classes described in Chapter 20 or the queueing structures described in Chapter 21. The user inputs the following information a. The relative weight of arrivals. This is an integer between 1-100. b. The number of servers. This is an integer between 1-25. c. The relative weight of a server. This is an integer between 1-100. d....
In Java, complete the following: During the lunch hour, the ATM machine in a large office complex is in heavy demand. Customers complain that the waiting time is much too long. The local bank considering the addition of a second ATM machine. But first, the bank needs a few statistics to justify the cost of adding a second ATM machine. Using a Queue, simulate a waiting line at the ATM machine for a period of one hour. Make the following...
Q1. Write a program to simulate a grocery waiting queue. Your
program should ask the user if they want to add a customer to the
queue, serve the next customer in the queue, or exit. When a
customer is served or added to the queue, the program should print
out the name of that customer and the remaining customers in the
queue.
The store has two queues: one is for normal customers, another is
for VIP customers. Normal customers can...
C PROGRAM: In this assignment, you will use the concept of POSIX threads, semaphores and mutex locks. Consider a very small bank: XYZ. This bank has only one cashier (aka bank teller or customer representative) and a small waiting room for any incoming customers while the cashier is busy with other customer. There is a sofa which can only hold 5 people at maximum. The cashier can only serve one customer at any time. When the cashier is serving one...
Sorting Threads Assignment Overview Write a multithreaded sorting program in Java which uses the merge sort algorithm. The basic steps of merge sort are: 1) divide a collection of items into two lists of equal size, 2) use merge sort to separately sort each of the two lists, and 3) combine the two sorted lists into one sorted list. Of course, if the collection of items is just asingle item then merge sort doesn’t need to perform the three steps,...
Write in java language ================== Office Supplies Inc., an office supply store, services many customers. As customers’ orders for office supplies are shipped, information is entered into a file. Office Supplies bills their customers once each month. At the end of each month, the Chief Executive Officer requests a report of all customers sorted by their customer id (from lowest to highest). The report includes their bill balance and tax liability. Write a program to produce the outstanding balance report...