• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bank Simulator - doBusiness method help LinkedList/Queue  RSS feed

 
Rob Burns
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have to create a Bank Simulator project for class, and so far I have a few of the methods implemnted. But currently I am having trouble with the doBusiness method in the ServiceCenter class. Here is the code I have so far.

Main: BankSimulator



Server class:



Customer class:



I had to create the following class called ServiceCenter where getTime returns the time in the simulation which starts at 0 and increments on each step. An addCustomer method where we add a customer to the queue and displayed a message. A customerRemaining which returns true if a customer is currently being waited on. Lastly the doBusiness method which increments the time, if the server finished with a customer remove them from the queue, and if the server is free and there is a customer in the queue, begin serving them. I have the first few ones done except the doBusiness method I am stuck on. Does anyone have any tips?

The code listed above was created by Dave Reed and I take no credit for the code.

ServiceCenter class:



Any help at all or tips would be greatly appreciated. I've been trying to figure out how to code the doBusiness for a week now, but for some reason queues are my weakness. I'm also not sure if how the ServiceCenter class has been implemented correctly, so any criticism would be helpful as well. Thanks for reading and sorry for it being so long. Just wanted it to be detailed.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What are you trying to do? Are you trying to time how long each person is in the queue?
Are you familiar with the working of a Queue? You can read a bit about them in the Java Tutorials (look under interfaces and implementations). Note you have two ways to add an element to a queue and two to take it out the other end. One does nothing useful if the queue is empty/overfull and the operation is not feasible. The other throws an Exception.
If you are trying to time things, can you work out how to do that. You don't want to do it on screen, but on paper. When you have some idea how you would do it on paper or in real life if you were standing in the bank with a stopwatch, then you can think how to do it on screen.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (server == null)

What does that mean? Are you sure that is right?
 
Rob Burns
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where I am stuck is the doBusiness. When the doBusiness method is called in the main class, it is supposed to calculate the arrival time and the end time of a transition as well as checking to see if the server is still waiting on a customer. If the server is done with the customer I am supposed to remove them from the queue. If there are customers waiting in line and the server has no customers, it waits on the next one in line until there is no customers left in the queue which will cause the customersRemaining return false.

I am very new to queues and we're not covering them very closely in my class, so I am completely lost.

I'm not entirely sure if that's right or not, I've been reading out of the book but the implementation and class reference is different than what I am trying to program.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case there is a bit of hardware getting in your way. It is called a computer. Remove it from your sight.
Go to the nearest bank and watch people waiting for the counters. Then come back and tell us how you intend to time them. Without a computer. By the way, by server do you mean the person working at the bank?

At least I think you want to time people. If I am totally mistaken about the exercise, be sure to tell me. I think the exercise would be the same at shops, post offices or ticket counters, as at a bank.
 
Rob Burns
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can tell how to take the time of the transaction, my problem is implementation. It would be endTime - startTime which calculates the arrival of the customer to the service counter to the time they leave. I'm having difficulty understanding how to check if a server is waiting on a guest in terms of code, not theory or practical application. That is why I started the two if statements to see if they are true or false but I have no idea if that implementation is correct. There are no references anywhere and I am learning on my own at this point. I'm currently working on it now trying to make a makeshift method from the Java book I have. So far I have this.


 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Burns wrote:I'm having difficulty understanding how to check if a server is waiting on a guest in terms of code, not theory or practical application.


Then the first place I would look is at the server class. If you need to know whether the server is waiting on a guest, then the design should have included a method which tells you that.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!