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));
}
}
}
==============
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.