The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

wanna change the value in the map -- reposted

Posted by Mei-Tzu on September 27, 2000 at 10:41 PM

I have posted this message earlier, there was a mistake, and here is my problem:

(1)a class called � Customer�,
public class Customer {
�..//instance variables and other methods

public int getArrivalTime() {

//use total minutes to generate
// an arrival time between 9:00 to 17:00

arrivalTime = (int)(480*Math.random()) + 540; return arrivalTime;
}

public int getQueTime (){
//need to be calculated in another class -- TellerList
return queTime;
}

(2)another class called �CustomerList�
in this class I create a LinkedList customers

(3) the third class called �TellerList� with three tellers
public class TellerList {
private Map tellers;

public TellerList (){

//the key represent the teller's name,
// the value represent the teller's first available time
// the value will be modified later

Map tellers = new HashMap();
tellers.put("Teller1", new Integer(536));
tellers.put("Teller2", new Integer(537));
tellers.put("Teller3", new Integer(538));
}

public void runTeller() {
Set entries=tellers.entrySet();
Iterator it = entries.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
Object tellerName = entry.getKey();
Object availableTime = entry.getValue();
...... //need to replace the value here.
}
}
}


Problem 1:
Each teller is given an initial available time (the value, 536, 537, and 538). When a customer comes, it will find the first available teller(with the smallest value in the map). I also need to compare the customer's arrival time with the teller's available time so that I can calculate this customer's finish time, and this finish time will be this teller's next availabe time. Then I need to replace this teller's available time, ie, I need to replace the value associated with this teller. This will continue till all the customers are serviced. The problem is that When I use Map.Entry to get the value, it returns an Object,
I tried to do this way: int availableTime = entry.getValue(); but I got an error message. I need to compare the availableTime with the arrivalTime, but since I can't replace
(Object availableTime = entry.getValue();) with (int availableTime = entry.getValue();), I can't compare the arrival time with the available time and as a consequence, I can't calculate the finish time for the customer and the queTime. I am really helpless, am I doing a silly thing?

Problem 2:
How to use the setValue() method?

Problem 3:
Let's say I can get the queTime for each customer, how do I hold it? This queTime will be used in other class( to be printed out).

I really appreciate any opinions, just to get me out of here. Thank you!!






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us