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 HashMap

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

I have some problems with my HashMap
Currently I have three classes : Customer, CustomerList, and Teller

(1)
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

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(keys)
public class TellerList {
private Map tellers;

public TellerList (){
Map tellers = new HashMap();
tellers.put("Teller1", "536");//first give each teller an availableTime
tellers.put("Teller2", "537");
tellers.put("Teller3", "538");
}
public void runTeller() {
Set entries=tellers.entrySet();//search for the key/value in the map
Iterator it = entries.iterator();

while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
Object tellerName = entry.getKey();
Object availableTime = entry.getValue();
Problem 1:
To my understanding, I can replace the value using setValue(), and this is what I want. The value in the map is the teller�s available time, and this changes when a customer comes and leaves. Is it the right to use the HashMap?
Problem 2:
I tried to replace ( Object tellerName = entry.getKey() ) with (String tellerName = entry.getKey()) as well as the available time in the TellerList class, but I got error messages. I wanna compare the
AvailableTime with the customer�s arrival time later in the class, how can I compare an
Object availableTime with an Integer arrivalTime?
Problem 3:
How to use the setValue() method?

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