السلام عليكــم ورحمـة الله وبركاتــه ،،
أشكر كل من ساعدني في إكتشاف خطأي في موظوعي السابق
Telephone Directory
.... وأنا إن شاء الله سأدرج الحل الصحيح في وقت قريب ...ليستفيد منه الجميع وليتعلموا أيضا من أخطائنا ...
.... ولحسن الحظ .... قرر دكتور المادة اليوم أن يعطينا فرصة أخرى بأن نحل مسائل جديدة و تتضمن نفس الفكرة ..
لهذا أنا سأدرج هنا الأسئلة .... وأريد من يساعدني فيها ... أنا سأحاول حلها ... وأرجوا أنتم أيضا أن تحاولوا معي ...
للتبيه تسليمه غدا .....
إليكم الأسئلة ....
Q1.
Write a Java class called CountryMap that will be used to keep information about the countries and their capitals in a HashMap. So, the country name is the key, and the capital is the value associated to the key.
An example of an entry of the HashMap is ("UAE", "Abu Dhabi").
This class should implement the following methods:
Public void addCountry (String country, String capital)
Public String lookupCapital(String country)
Public void removeCountry(String country)
Public void removeAllCountries()
//the following method checks if the map contains a specific key
Public boolean containsCountry(String country)
//the following method checks if the map contains a specific value
Public boolean containsCountry(String capital)
Note:
§ Remember to import java.util.HashMap
§ Some of the above methods require using some methods of the class HashMap. Find appropriate methods from the HashMap documentation.
Q2.
Write a Java class called CountryTester to test the CountryMap class defined in question1.
In the main method of this class, you have to implement the following tasks:
§ Instantiate an object of the CoutryMap class
§ Add the following entries to the map:
- ("UAE", "Abu Dhabi")
- ("Qatar", "Doha")
- ("Bahrain", "Manama")
- ("Oman", "Maskat")
- ("Saudi Arabia", "Riyad")
§ Find out in the map the capital of "Bahrain"
§ Find out in the map the capital of "Egypt"
§ Remove the entry of "Qatar" from the map.
§ Add the following entries to the map:
- ("Jordan", "Aman")
- ("Morocco", "Rabat")
§ Find out in the map if there is any entry for which the capital is "Manama".
§ The method keySet() of the HashMap returns, when it is invoked, a set containing all keys of the map. Use this method together with the iterator of the set to print out all the countries of the map.
§ Remove all entries from the CountryMap object.
وجزاكم جميعا كل الخير ....