Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a java program. I have most of the code but need help with it a

ID: 3689204 • Letter: I

Question

I need help with a java program. I have most of the code but need help with it and making sure that it is correct. I have the detailed assignment

Your assignment is to write a program named BankSim.java to carry out an event - driven bank simulation involving a single line of customers being served by a single teller. An event - driven simulation is based on the sequential processing of a series of events that represent the significant activitiesof the process being simulated. In this case, the following events must be simulated.

1.

The arrival of a new customer into the bank.

2.

The completion of a transaction between a customer and a bank teller.

The purpose of such simulations is to collect important statistical information to allow managers to make an informed decision about the number of service employees to be used to handle customer transactions. For this simulation, your output must produce the following statistics.

Total number of people processed.

Average and maximum wait time.

Minimum and maximum transaction times.

Maximum line length (include the customer being served).

BONUS: Average line length. This should be weighted according to time. Suppose the simulation lasts 20

minutes. If for 5 minutes the line length is 0, for 6 minutes the line length is 1, and for 9 minutes the line length is

2, then the average line length is given by ((0 * 5) + (1 * 6) + (2 * 9))/20 = 1.2

Other program requirements are specified below.

Input Format

The input is the information about arrival events. The format of the input is one or more lines that consist of two integersthat provide the necessary information for a single arrival event. The first integer specifies <arrival_time>, and the second integer specifies <duration>. The units for <arrival_time> is elapsed minutes since the start of the simulation. The units for <duration> is the time in minutes required to complete the customer transaction. More specific requirements are the following.

The data should be ordered by arrival time (earliest to latest).

The data will come from the standard input stream. It is strongly recommended that you place sample inputs in files and then use input redirection to read in the events. End -of-file (EOF) is the terminator of input. Thus, the Scanner method has_next()can be used to detect end of input.

Data Structures

1.

EventItem

the information for a single event (arrivalor departure). EventItem is a provided class definition. Details are provided on the WWW page for the assignment.

2.

<bank_queue> - models the queue of customers in the bank. It should include both the customers waiting for service as well as the current customer receiving service. The <bank_queue> should be implemented as a Java API Queue interface with object type EventItem. Use the Java API class LinkedList as your implementing class.

3.

<event_list> - an ordered list of events that need processing. It normally consists of the next arrival event and the next departure event. Ordering is based on time (ascending order), and the EventItem API provides a compareTo method that will produce the necessary result to help you determine the order. Initially , the <event_list> will be empty, and at the end of the simulation, the final event will be a single departure event. You must implement the <event_list> using the Java API List interface. You may choose either ArrayList or LinkedList as the implementing class.

Algorithm

The concept of an event-driven simulation is that the system will process a time - ordered sequence of events, arrival events or departure events according to the following guidelines. Note that <current_time> denotes the current time of the simulation. The initial value of <current_time> at the start of the simulation is 0. The main control loop repeatedly removes and processes the first item on the <event_list> until no items remain. The process for handling the two types of events is described below.

Arrival events

When a customer arrives <current_time> should be updated to the <arrival_time> of the customer. In addition, the

customer should be added to the <bank_queue>. Additional processing may be required depending on the state of the simulation.

As each customer arrives, the simulation will be in one of two states.

1.

The bank teller is free and can process the customer immediately; or

2.

The bank teller is currently busy with another customer, and the new arrival must go to the back of the line. If the simulation is in state #1,a departure event is created and added to the <event_list> that specifies the time at which the customer’s transaction will be completed. This time is equal to <current_time> + < duration>.The final actionfor both states is to read the next arrival event from the input (if one exists) and add it to the <event_list>.

Departure events

When a departure event occurs, then

<current_time>

should be updated to the time associated with the departure event (i.e.,the time at which the customer’s transaction is completed). In addition, this customer should be removed from<bank_queue>. At this point the simulation will be in one of two states.

1.

The <bank_queue>

is empty. That is, no customers are waiting; or

2.

There is another customer in the

<bank_

queue

>

.

For state #1

no further action is needed, and the program should

process the next event.

For state #2

, a d

eparture event should be created. This signifies that the customer’s transaction has been initiate

d with the

bank teller. As before the completion time for the bank teller will be

<current_time>

+

<

duration

>

where

<current_time>

has just been updated as noted above.

Statistics

Note that as part of the event processing, data from the simulation is us

ed to calculate the necessary items required for

computing the required statistics.

Processing Trace

A detailed description for the following input and output of a small simulation is provided below.

Input

1 5

2 5

4 5

20 5

Output

Processing an arrival

event at time:

1

Processing an arrival event at time:

2

Processing an arrival event at time:

4

Processing a departure event at time:

6

Processing a departure event at time:

11

Processing a departure event at time:

16

Processing an arrival event at time:

2

0

Processing a departure event at time:

25

Step 1:

Initialize <current_time> to 0.

Initialize the

<event_list>

with the first arrival event (1 5).

Step 2: Extract

arrival

(1 5) from the

<event_list>

.

Update

<current_time>

to the arrival time (1)

, generate the appropriate

output messa

ge,

and add the event to the <bank_queue>. Since this customer is at the front of the <bank_queue>

set up a

d

eparture event with the value (6 0) (where 6 =

<current_time>

(1) +

<

duration

>

(5))

, and add this departure event to the

<event_list>

.

Read the nex

t arrival event (2 5) and add it to the

<event_list>

.

Step 3: Extract

arrival

(2 5) from the

<event_list>

.

Update

<current_time>

to the arrival time (2)

, generate the appropriate

output message,

and add

the event to the <bank_queue>.

Since the bank que

ue is not empty

, no new departure event is

created. Read the next arrival event (4 5) and add it to the <event_list>

Step 4:

Extract

arrival

(4 5) from the <event_list>. Update

<current_time>

to the arrival time (4)

, generate the appropriate

output mess

age,

and add

the event to the <bank_queue>.

Since the bank queue is not empty, no new departure event is

created. Read the next arrival event (20 5) and add it to the <event_list>

Step 5: Extract

departure

(6 0) from the

<event_list>

. Update

<current_

ti

me

>

to 6

, generate the appropriate output

message,

and remove the

event

(1 5) from the front of the

<bank_

queue

> to simulate the customer completing the

transaction with the bank teller

. Take the new front item of the

<bank_

queue

>

(2 5) and create a depar

ture event (11 0) and

add it to the

<event_list>

.

Step 6:

Extract

departure

(11 0) from the <event_list>. Update <current_time> to 11

, generate the appropriate output

message,

and remove the event (2 5) from the front of the <bank_queue>. Take the new f

ront item of the <bank_queue> (4

5) and create a departure event (16 0) and add it to the <event_list>.

Step 7:

Extract

departure

(16 0) from the <event_list>. Update <current_time> to 16

, generate the appropriate output

message,

and remove the event (4

5) from the front of the <bank_queue>. At this point the <bank_queue> will be empty so

no new departure event is created.

Step 8: Extract

arrival

(20 5) from the <event_list>. Update

<current_time>

to the arrival time (20)

, generate the

appropriate outp

ut message,

and add the event to the <bank_queue>. Since this customer is at the front of the

<bank_queue> set up a

departure event with the value (25 0), and add this departure event to the <event_list>. Since we

have reached the end of the arrival event

input, no new arrival event can be read and added to the <event_list>.

Step 9: Extract

departure

(25 0) from the <event_list>. Update <current_time> to 25

, generate the appropriate output

message,

and remove the event (20 5) from the front of the <bank_q

ueue>. At this point the <bank_queue> will be empty

so no new departure event is created.

Step 10: The event list is empty so the simulation is at an end. Print the final statistics and terminate the program

Explanation / Answer

my customer class

   public class Customer

   {

        int clock, currentTime;

        public Customer()

        {}

        public Customer(int theTime)

        {

            clock=theTime;

        }

  

        public int getCurrent(int current)

        {

             currentTime=clock-current;

             return currentTime;

        }

   }


my teller class

   import java.util.Random;

   import java.util.Scanner;

   public class Teller

   {

  

        Customer c=new Customer();

  

        int runTime, customerArrival, transactionTime;

        Queue q=new Queue();

        int customers=0;

  

      public Teller(int run, int maxNewCustomer, int maxHandle)

         {

            runTime= run;

            customerArrival= maxNewCustomer;

            transactionTime = maxHandle;

         }//end constructor

  

         public int runTime(){

           return runTime;

         }//end runTime

  

         public int getTransactionTime(){

           return transactionTime;

         }//endTransactionTime

  

         public int getCustomerArrival(){

           return customerArrival;

         }//end getCustomerArrival

  

         public void Run()

          {

             Random rand= new Random();

             int newArrival = rand.nextInt(customerArrival);

              customerArrival=newArrival;

              q.empty();

              int time;

              Customer next=new Customer();

              for(time=0;time<runTime; time++)

              {

                if(q.empty()==false)

                {

                if(c.currentTime>=customerArrival)

                  {

                    q.enqueue(next);

                    customers++;

  

                  }else if(customerArrival>transactionTime)

                  {

  

                      q.dequeue();

                      customers++;

                      int nextArrival = rand.nextInt(customerArrival);

                      customerArrival=newArrival;

                      nextArrival=c.clock+nextArrival;

                      }//end if

                }//end if

              }//end for

          }//end Run

          public void report()

          {
              int totalTime=c.clock;

              System.out.println(totalTime);

              int Average=totalTime/customers;

                      System.out.println(Average);

              int numberServed=customers;

                      System.out.println(numberServed);

              if(q.empty()==true)

              {

                  System.out.println(q.toString());

                  System.out.println(c.clock);

              }//end if
          }//end report

           public static void main(String[]args)

              {

                  Scanner key=new Scanner(System.in);

                  System.out.println("how many seconds to run: ");

                  int newRunTime=key.nextInt();

                  System.out.println("max time between customers: ");

                  int newCustomerArrival=key.nextInt();

                  System.out.println("max processing time: ");

                  int newTransTime=key.nextInt();

                  Teller t= new Teller(newRunTime,newCustomerArrival,newTransTime);

                  t.Run();

                  t.report();

              }//end main

   }


the queue class that was given

   public class Queue<T> {

        private Node<T> first;

        private Node<T> last;

        T newOne;

        private int count;

        public Queue () {

           last = new Node<T>();

           first = new Node<T>(null,last);

           count=0;

        }

  

        public String toString() {

            String ret = "";

            Node<T> r = first.getNext();

            for (; r!=last; r=r.getNext())

                ret += r.getData() + " ";

            return "first " + ret + "last";

        }

      public T dequeue() {

            T ret;

            if (count==0) return null;

            ret = first.getNext().getData();

            first = first.getNext();

            count--;

            return ret;

        }

      public void enqueue(T newData) {

            last.setData(newData);

            last.setNext(new Node<T>());

            last = last.getNext();

            count++;

        }

        public boolean empty() { return count==0; }

        public int length() { return count; }

   }

and node class that was given

   public class Node<T> {

        private T data;

        private Node<T> next;

        public Node(T d, Node<T> n) { data=d; next=n; }

        public Node(T d) { data = d; next = null; }

        public Node() { data = null; next = null; }

        public T getData() {return data;}

        public Node<T> getNext() {return next;}

            public void setData(T d) { data = d; }

        public void setNext(Node<T> n) { next = n; }

        public String toString() { return "" + data;
        }

   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote