Author: Marty Stepp (on 07/08) Write a function named input_stats that accepts a
ID: 3594679 • Letter: A
Question
Explanation / Answer
import java.util.*;
public class HashTableDemo {
public static void main(String args[]) {
// Create a hash map
Hashtable balance = new Hashtable();
Enumeration names;
String str;
double bal;
balance.put("aaa", new Double(3434.34));
balance.put("bbb", new Double(123.22));
balance.put("ccc", new Double(1378.00));
balance.put("ddd", new Double(99.22));
balance.put("eee", new Double(-19.08));
// Show all balances in hash table.
names = balance.keys();
while(names.hasMoreElements()) {
str = (String) names.nextElement();
System.out.println(str + ": " +
balance.get(str));
}
System.out.println();
// Deposit 1,000 into aaa's account
bal = ((Double)balance.get("aaa")).doubleValue();
balance.put("aaa", new Double(bal+1000));
System.out.println("aaa's new balance: " +
balance.get("aaa"));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.