Question
I keep getting an error and i do not know how to fix it. The program has to wrote in java i will post the
I keep getting an error and i do not know how to fix it. The program has to wrote in java i will post the question along with the code that I have so far.
Write a discreet event simulation of a bank. Data for the simulation is contained in an ASCII file titled bank.txt. The format of the file consists of an unspecified number of lines with each line containing two integers and a string: time_of_entry (integer), transaction_time (integer) and a customer name (string), sorted by ascending time_of_entry. Each field is separated by white space. Sample
0 7 James Bond
0 9 Auric Goldfinger
4 10 Miss Moneypenny
9 4 M
12 6 Q
For each click of the (integer) simulation clock, these actions occur in order
- Check if customer enters bank, if so assign a queue
- Check if customer completes transaction, if so exits bank.
- Check each queue if the teller is free and if so starts transaction.
For each event, output the a message to event long file. The wait time is the difference between when a customer enters the bank and their transaction starts. The simulation continues until all the customers in the file have their transaction completed. The program should output 1) Average wait time 2) maximum wait time, 3) Average Idle time of tellers (time not spent with a customer). 4) Maximum idle time of a teller, 5) total time of the simulation, 6) Teller Efficiency (sum of transaction times/(total time of simulation)
The program should run the same the simulation multiple times with these parameters:
- Tellers count of 2, 3, 4, 5
- Customers form a queue behind each teller when the enter the bank (choose the shortest one).
- Customer join a single wait queue when they enter the bank, they leave the queue when any teller comes open.
For each of the (4*2=8) simulations output the six numbers.
Java Code I have so far
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; class Event { private int time; // time of event private String type; // type of Event (arrival or departure) Event() { time = 0; type = ""; } Event(final int time, final String type) { this.time = time; this.type = type; } public int getTime() { return time; } public void setTime(final int time) { this.time = time; } public String getType() { return type; } public void setType(final String type) { this.type = type; } } class ListComparator implements Comparator { @Override public int compare(final Event o1, final Event o2) { return o1.getTime() - o2.getTime(); } } class BankSimulation { private final List queue; private int totalWaitingTime; BankSimulation() { queue = new ArrayList(); totalWaitingTime = 0; } public void runSimulation() throws FileNotFoundException { final Scanner filereader = new Scanner(new File("/Users/blakethomas/Desktop/Bank.txt")); int previousDepartureTime = 0; // until there is input while (filereader.hasNext()) { final Event arrivalEvent = new Event(filereader.nextInt(), "arrival"); final int processingTime = filereader.nextInt(); int departureTime = 0; if (arrivalEvent.getTime() > previousDepartureTime) {// immediate processing departureTime = arrivalEvent.getTime() + processingTime; } else {// wait to get processed departureTime = previousDepartureTime + processingTime; } previousDepartureTime = departureTime; totalWaitingTime = totalWaitingTime + departureTime - arrivalEvent.getTime() - processingTime; final Event departureEvent = new Event(departureTime, "departure"); // add the arrival and departure events to queue. queue.add(arrivalEvent); queue.add(departureEvent); } filereader.close(); // sort the list on basis of timings Collections.sort(queue, new ListComparator()); } public void printResults() { System.out.println(" Simulation Begins"); for (final Event event : queue) { if (event.getType().equals("arrival")) { System.out.println("Processing an arrival event at time: " + event.getTime()); } else { System.out.println("Processing a deparature event at time: " + event.getTime()); } } System.out.println(" Simulation Ends"); System.out.println(" Final Statistics: "); System.out.println(" \tTotal number of people processed: " + queue.size() / 2); System.out.println("\tAverage amount of time spent waiting: " + (float) totalWaitingTime / (queue.size() / 2)); } public static void main(final String... args) throws FileNotFoundException { final BankSimulation bankSimulation = new BankSimulation(); bankSimulation.runSimulation(); bankSimulation.printResults(); } }
Any time I run it i get this error what am i doing wrong
Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at BankSimulation.runSimulation(Event.java:59) at BankSimulation.main(Event.java:98)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started