Total members 11894 |It is currently Sat Nov 23, 2024 1:43 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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));
}
}
}




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




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  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     -  
 inner class that is a member of an outer class?     -  
 Define class inside another class C++     -  
 i have problem     -  
 MVC problem....     -  
 load class to applet- load frame class to applet     -  
 Windows problem!!!     -  
 Problem with skymiles_red     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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