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 instead
include a single add method that adds the item in the correct
(sorted) spot, smallest items at the head. Use this method
header: public void add(E e)
• Indicates that the generic item will have implemented the
Comparable interface by specifying the class in this 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:
• Set the customerNumber (use a static class variable for
this)
• Set storeArrivalTime (use the simClock, which will be a
parameter to the constructor)
• Set shoppingLength (a random number between 5 and 45)
There should be accessor (getter) methods for the following:
• customerNumber
• storeArrivalTime
• shoppingLength
• checkoutArrivalTime (storeArrivalTime + shoppingLength)
• checkoutLength (the integer ceiling of shoppingLength/5).
Include a toString method that displays all information for the
customer
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:
• A CustomerList – a sortedList of customers representing the
customers currently shopping
• An array of Cashiers (checkout lanes)
Output files needed:
•You will need two output files: one to store the summary
information and one to store details of the simulation.
Other:
• A simulation clock (an integer variable)
• Declare other variables as needed to store the necessary
counters and statistics, and to manage the simulation.
Simulation procedure:
1. Declare data objects, files, etc.
2. Get input:
• Number of open checkout lanes (integer, user must enter a number
>= 1)
• Length (in minutes) of the simulation (int, user must enter a
number >= 10)
• Number of customers expected to enter the store during each hour
(integer between 1 and 60)
3. Initialize variables (create the
appropriately-sized array of cashiers; set simulation clock to 0,
number of customers to 0, etc.)
4. Begin simulation loop (a counted loop that
increments the simClock each iteration until simulation length is
reached; start the counter at 1):
• If a new customer has arrived to the store (determined by a
random function described below):
• Create a new customer (use the simClock as
storeArrivalTime)
•Increment the number of customers created.
• Add customer to customer list
• If customers are ready to check out (when their
checkOutArrivalTime == simulation clock)
• Remove the customer from the customer list and add the customer
to cashier with shortest checkout line. Keep in mind more than one
customer could be ready to check out during each clock cycle.
• Update cashiers. For each cashier:
• If the cashier’s finishTime <= simulation clock, the cashier
is available to handle another customer from the queue. If that
cashier’s line is not empty:
• Call the serveNextCustomer method for that cashier
• Increment number of customers served
• Calculate how long this customer was waiting since entering the
checkout line and increment totalWaitTime accordingly.
• Output the customer details to the details output file.
5. After the simulation loop, output all
input values to the summary output file. (number of
checkout lanes used, length of the simulation, number of customers
expected to enter the store during each hour)
6. After the simulation loop, output all simulation
statistics to the summary output file:
• Number of customers who entered the store during the
simulation
•Number of customers still shopping (not in line)
•Number of customers waiting in a checkout line but not yet being
served
•Number of customers who have been or are currently being served
by cashiers
•Average wait time for all customers who have been or are
currently being served (rounded to two places to the right of the
decimal)
7. Write a message to the console indicating that
the simulation is finished, and where the simulation information
can be found (state the file names for the details and summary
information).
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:
•Calculate the arrival probability per hour (expected # of
customers per hour / 60 * 100). This needs to be of type
double
• Generate a random integer between 0 and 100
• If the number is less than or equal to the arrivalProbability,
assume a new customer has arrived.
• If the number is greater than the arrivalProbability, no
customer has arrived.
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.
1. Create queue class and thoroughly test all methods with a
separate driver program
2. Create sorted list class and thoroughly test all methods with a
separate driver program
3. Create the Cashier class and write a driver to thoroughly test
all methods.
4. Create the Customer class and write a driver to thoroughly test
all methods.
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.
// Java orogram to demonstrate working of Queue
// interface in Java
import java.util.LinkedList;
import java.util.Queue;
public class Queue
{
Queue<Integer> q = new LinkedList<>();
// Adds elements {0, 1, 2, 3, 4} to queue
for (int i=0; i<5; i++)
q.add(i);
// Display contents of the queue.
System.out.println("Elements of queue-"+q);
// To remove the head of queue.
int removedele = q.remove();
System.out.println("removed element-" +
removedele);
System.out.println(q);
// To view the head of queue
int head = q.peek();
System.out.println("head of queue-" + head);
// Rest all methods of collection interface,
// Like size and contains can be used with this
// implementation.
int size = q.size();
System.out.println("Size of queue-" + size);
}
package core;
/**
* Wall clock for checking the simulation time.
*/
public class SimClock {
private static double clockTime = 0.0;
private static SimClock clock = null;
private SimClock() {}
static {
DTNSim.registerForReset(SimClock.class.getCanonicalName());
reset();
}
/**
* Get the instance of the class that can also change the
time.
* @return The instance of this clock
*/
public static SimClock getInstance() {
if (clock == null) {
clock = new SimClock();
}
return clock;
}
/**
* Returns the current time (seconds since start)
* @return Time as a double
*/
public static double getTime() {
return clockTime;
}
/**
* Returns the current time rounded to the nearest integer
* @return Time as integer
*/
public static int getIntTime() {
return (int)Math.round(clockTime);
}
/**
* Advances the time by n seconds
* @param time Nrof seconds to increase the time
*/
public void advance(double time) {
clockTime += time;
}
/**
* Sets the time of the clock.
* @param time the time to set
*/
public void setTime(double time) {
clockTime = time;
}
/**
* Returns the current simulation time in a string
* @return the current simulation time in a string
*/
public String toString() {
return "SimTime: " + clockTime;
}
/**
* Resets the static fields of the class
*/
public static void reset() {
clockTime = 0;
}
}
Public class Customer{
int CustomerNumber;
int storeArrivalTime;
int Shopping Length;
Customer(int CustomerNumber cn, storeArrivalTime SimTime){
CustomerNumber=cn;
storeArrivalTime=SimTime;
Shopping Length=int random = (int)(Math.random() * 44 + 1);
}
public int getCustomerNumber() {
return this.cn;
}
public int getstoreArrivalTime() {
return this.SimTime;
}
public int getShoppingLength() {
return this.random;
}
public int getCheckoutArrivalTime() {
int Ck=SimTime+random;
return this.Ck;
}
public int getcheckoutLength() {
int ckt=(random/5);
return this.ckt;
}
public void setCustomerNumber(int Cn) {
this.cn=Cn ;
}
public void setstoreArrivalTime(int Tm) {
this.SimTime = Tm;
}
public void setShoppingLength(int rn) {
this.random = rn;
}
public void setCheckoutArrivalTime(int Ckt) {
this.Ck = Ckt;
}
public void setcheckoutLength(int cr) {
this.ckt = cr;
}
public String toString(){//overriding the toString() method
return CustomerNumber+" "+storeArrivalTime+"
"+ShoppingLength;
}
}
}
}
public class Cashier extends Queue{
int finishTime;
Cashier(){
finishTime=0;
}
private static String qitems[] = new String[7];
private static int front = 0, end = 0;
public boolean addcustomer() {
Scanner input = new Scanner(System.in);
System.out.print("Enter Customer to the queue :");
qitems[end] = input.next();
end++;
}
public Customer ServeNextcustomer(int Sim){
if (q.peak==null){
return null;
}
else
q.remove;
int finishTime=Sim+checkoutLength;
return Customer;
}
public static void main(String[] args)
{
Customer Cust=new Customer();
Cashier[] Cash;
int counter = 0;
double even = 0;
double odd = 0;
double sum = 0;
int input = 0;
int large = 0;
int small = 0;
double average;
System.out.print("Enter a series of values (0 to quit):
");
Scanner in = new Scanner(System.in);
while ((input = in.nextInt()) != 0) {
small = in.nextInt();
large = in.nextInt();
if (input != 0)
sum = input + sum;
counter++;
if (input > large)
large = input;
if (input < small)
small = input;
if (input % 2 == 0)
even = even + 1;
else
odd = odd + 1;
}
if (counter > 0) {
average = sum / counter;
System.out.println("simulation is finished " + cn);
} else {
System.out.println("Error.");
}
}
}
}
Needs Help with Java programming language For this assignment, you need to write a simulation program...
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...
USE JAVA PROGRAMMING LANGUAGE See all photos + Add to a ♡ Search Edit & Create Share . Benny the Barber owns a one-chair shop. They told Benny that customers are not happy with waiting in lines and not get processed in order they arrived. As computer scientist, you are going to help Benny to write a Java program to manage waiting lines and to process customers in the same order they arrive. Here are the functional requirements of the...
Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should declare the following collection of classes: 1) An abstract class Customer: each customer has: firstName(String), lastName (String), age (integer), customerNumber (integer) - The Class customer has a class variable lastCustomerNumber that is initialized to 9999. It is used to initialize the customerNumber. Hence, the first customer number is set to 9999 and each time a new customer...
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...
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...
1- Write a code for a banking program. a) In this question, first, you need to create a Customer class, this class should have: • 2 private attributes: name (String) and balance (double) • Parametrized constructor to initialize the attributes • Methods: i. public String toString() that gives back the name and balance ii. public void addPercentage; this method will take a percentage value and add it to the balance b) Second, you will create a driver class and ask...
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,...
Really need help with this. This is for my Advanced Java Programming Class. If anyone is an expert in Java I would very much appreciate the help. I will provide the code I was told to open. Exercise 13-3 Use JPA to work with the library checkout system In this exercise, you'll convert the application from the previous exercise to use JPA instead of JDBC to access the database. Review the project Start NetBeans and open the project named ch13_ex3_library that's...