hello Friends:;

I have question and I wont your help.. I do it,but I'm stuk in printing :icon_cry:.. This the code,
I hope you can help ,, Thanks

Write a class TelephoneDirectory. It has a telephoneList attribute as a HashMap. The TelephoneDirectory has the following methods:
a.addTelephoneEntry ( TelephoneNumber number, Person person )
b.removeTelephoneEntry ( TelephoneNumber number )

CODE:icon_wink: words in red I'm not sure this or other statment correct

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class TelephoneDirectory {
HashMap telephoneList;
public TelephoneDirectory (){
telephoneList = new HashMap ();

public void addTelephoneEntry(TelephoneNumber Number , Person person ){

// Add the person with its key to the telephoneList
Set myKeys = telephoneList.keySet();
Iterator i= myKeys.iterator();
Number = (TelephoneNumber)i.next();
person = (Person) telephoneList.get(Number);
*/ telephoneList.put(Number,person);


public void removeTelephoneEntry(TelephoneNumber Number){

public void PrintTdirectory(){
Set myKeys = telephoneList.keySet();
Iterator i= myKeys.iterator();
TelephoneNumber Number = i.next();
System.out.print( Number+ " ");

6 Years
Discussion Span
Last Post by JamesCherrill

Stuff in red seems unnecessary. In the print you can use the number to get the corresponding name and print that out as well.
ps: Make sure your code is properly indented, and use CODE tags when posting.


What do you main when you said that I can use the number to get the corresponding name and print that out as well


You have a HashMap, with the number as key and the name as value. There's a method "get" for HashMaps that gives you the value corresponding to a given key, so you can then get the name, and print both the name and number together.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.