Question

Please use JAVA program language Discrete event simulation is to simulate events occurring at discrete time...

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) Write a class Bank with an attribute eventList, which is a list of Event. Add a method generateEvents(int n) which generates n random customer arrival events (with event type 0) and put them into eventList in the order of increasing arrival times. The arrival time of the first customer is a random integer between 0 to 10 (inclusively). Similarly, after the first customer has arrived, the time to wait for the next customer to arrive, the interarrival time, is also a random integer between 0 to 10. Other future customer arrivals are similar. For example, if the first customer arrives at 3 and the next 2 interarrival times are 2 and 4, the actual customer arrival times are 3, 5 (=3+2) and 9 (=5+4)

(c) Write a method waitingTime(int serviceTime) of Bank which returns the average waiting time of the customers whose arrival times are in eventList, where serviceTime is the time each customer being served at the bank counter. In other words, the servicing time of each customer is the same.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE: Java

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

This is a very big question.
I have solved all of them.
Please give me an upvote dear, Much Appreciated.!!

Event.java
public class Event
{
    // fields
    private int time;
    private int type;

    // Constructor
    public Event(int time, int type) {
        this.time = time;
        this.type = type;
    }

    // Getters and Setters
    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "Event{" +
                "time=" + time +
                ", type=" + type +
                '}';
    }
}

Bank.java

import java.util.*;
public class Bank
{
    ArrayList<Event> eventList;
    // (b)
    void generateEvents(int n)
    {
        // generate n random events
        eventList = new ArrayList<>();
        int arrivalTime = 0;
        for(int i=0;i<n;i++)
        {
            // create an event
            int time = new Random().nextInt(10);
            arrivalTime += time;
            Event event = new Event(arrivalTime, 0);
            // add that event to the list
            eventList.add(event);
        }
    }
    // (c)
    double waitingTime(int serviceTime)
    {
        double sum=0;
        // loop through the event list
        for(int i=1;i<eventList.size();i++)
        {
            int diff = eventList.get(i).getTime() - eventList.get(i-1).getTime();
            // check if the difference is negative
            if(serviceTime - diff  > 0) {
                // add the waiting time
                sum += serviceTime-diff;
            }
        }
        // return the average time
        return sum / eventList.size();
    }
}


TestBank.java

public class TestBank
{
    public 
  • static void main(String[] args) {
            // create some 5 random events
            Bank bank = new Bank();
            bank.generateEvents(5);
            // print the events generated
            System.out.println("The Events are: "+bank.eventList);
    
            // calculate the average waiting time with service time 2
            System.out.println("The Average waiting time with service time=5 is: "+bank.waitingTime(5));
            System.out.println("The Average waiting time with service time=7 is: "+bank.waitingTime(7));
            System.out.println("The Average waiting time with service time=9 is: "+bank.waitingTime(9));
            System.out.println("The Average waiting time with service time=11 is: "+bank.waitingTime(11));
            System.out.println("The Average waiting time with service time=13 is: "+bank.waitingTime(13));
        }
    }
    

Add a comment
Know the answer?
Add Answer to:
Please use JAVA program language Discrete event simulation is to simulate events occurring at discrete time...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events...

    Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in the bank. Maintain the arrival events and departure events in an ADT event list, sorted by the time of the event. Use a reference-based implementation for the ADT event list The input is a text file of arrival and transaction times. Each line of the file contains tiie arrival time and required transaction time for a customer....

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    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...

  • Question 1 Simulate the operation of a first-in-first-out queuing system until time TE = 30 minutes,...

    Question 1 Simulate the operation of a first-in-first-out queuing system until time TE = 30 minutes, using the interarrival and service-times given below (in minutes) in the given order. Interarrival times: 4, 3, 1, 1, 5, 7, 10 Service times: 4, 4, 6, 9, 8, 7, 4, 6 Given that the first arrival occurs at time t = 0, create a record of hand simulation (on the table given in the last page) using the event-scheduling algorithm and compute the...

  • Java Project For this assignment, you will write a simulation program to determine the average waiting...

    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: delete the addfirst, addlast, and add(index) methods and instead include a single add method...

  • In java please. SumOfPowerOfTwo The following program can be done in a single class. Write a...

    In java please. SumOfPowerOfTwo The following program can be done in a single class. Write a program that requests and reads in a integer number between 1 and 40 inclusively. Repeat the loop until a proper number is entered. Call the method powersOfTwoSum with the number as the actual parameter. Expect a value of type long as a return value. powersOfTwoSum(int number) This method must use a recursive technique to return the sum of the powers of two from the...

  • Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able...

    Question set 1 (Java) object oriented: 1.Write a class called Student. The class should be able to store information regarding the name, age, gpa, and phone number of a Student object. Please write all the setter and getter methods. Finally, write a Demo class to demonstrate the use of the class by creating two different objects. 2.Use the same Student class from the previous problem. This time,you will write a different Demo class, in which you will create three Student...

  • Write a program that simulates a checkout line at a supermarket. The line is a queue...

    Write a program that simulates a checkout line at a supermarket. The line is a queue object. Customers (i.e., customer objects) arrive in random integer intervals of from 1 to 4 minutes. Also, each customer is serviced in random integer intervals of from 1 to 4 minutes. Obviously, the rates need to be balanced. If the average arrival rate is larger than the average service rate, the queue will grow infinitely. Even with “balanced” rates, randomness can still cause long...

  • Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I...

    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...

  • 2. If an equal likelihood of each of several discrete events exists, in a simulation we...

    2. If an equal likelihood of each of several discrete events exists, in a simulation we can generate a random integer to indicate the choice. For example, in a simulation of a pollen grain moving in a fluid, suppose at the next time step the grain is just as likely to move in any direction—north, east, south, west, up, or down—in a three-dimensional (3D) grid. A probability of 1/6 exists for the grain to move in any of the six...

  • Java question Q1) Use the following code snippet which generates a random sized array with random...

    Java question Q1) Use the following code snippet which generates a random sized array with random contents to complete the following problems: public int [] createRandomArray() {         int size = (int) (Math.random() * 10) + 1;         int[] array = new int [size];         for (int i = 0; i < array.length; i++) {             array[i] = (int) (Math.random() * 10 ) + 1;         }         return array;     } Assignment...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT