Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Map Class problem

Tue Nov 30, 2010 10:06 am

I had some problem in Map in Java
I don't understand it very well

I try to solve some activity but I don't sure is correct
if any body can help me to check it to me

Thanks









The following table shows model area code and names of five star Houses in that area.

Area Code House names
141 “adison Sas”
142 “FourSeasons”
145 “life Regency”
147 “Sartoon”

This table is implemented by instances of a class called HouseCatalogue.

(a) Declare a private instance variable (Attribute) called HouseMap which should hold an unsorted map with integer keys and string values.

Private Map< Integer, String> HouseMap = new HashMap<Integer, String>();

(b) Write a zero-argument constructor of HouseCatalogue that initializes HouseMap to an empty map.
HouseMap.isEmpty();
(c) Write an instance method called addHouse() for the HouseCatalogue class that takes no arguments, and returns no value. This method should simply enter the four entries shown above into the HouseMap.
Public void addHouse()
{
HouseMap.put(141," Radison Sas") ;
HouseMap.put(142," ForSeason ") ;
HouseMap.put(145," Hayat Regency ");
HouseMap.put(147," Concord al-Salam ") ;
}



** an instance method called printHouse() for the HouseCatalogue class that takes an integer as argument and return a string value. This method should print the value (House name) of the area code that is equal to integer argument and return it. Otherwise it will return null.
Public string printHouse( int area)
{
for(Integer eachcode : HouseMap.keySet())
{ if ( HouseMap.keySet()== area)

{
System.out.println("House name is"+ HouseMap.get(eachcode));
}
}
}




==============



Post a reply
  Related Posts  to : Map Class problem
 Define class helper class to check the method existance     -  
 java abstract class,concrete class and interface     -  
 relationship between the Canvas class and the Graphics class     -  
 Define class inside another class C++     -  
 inner class that is a member of an outer class?     -  
 i have problem     -  
 MVC problem....     -  
 load class to applet- load frame class to applet     -  
 Windows problem!!!     -  
 Problem with skymiles_red     -