Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Unhappy Please answer me quickly

    hi ..


    I have some questions .. Please answer me as soon as possible

    - how can I Declare a private instance variable and it unsorted map with integer keys and string values??

    - how can I write constructor that initializes the class to an empty map ??

    - how can I Write an instance method for some class that takes no arguments, and returns no value.

    the method should simply enter the four entries



    thaks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sweet girl View Post
    Please answer me as soon as possible
    Please start here: Java Tutorials Big Index

    Then why not give it a try, any try and then post your attempt here. We'll be much better able to help you if we can see what you can and can't do, and also can see that you're willing to put in an attempt to study what needs studying.

    Luck and welcome to the forum.

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Map (Java Platform SE 6)

    Those two links can probably answer all of those for you.

    EDIT: Blast! Fubarable wins again. I'll get you next time...

  4. #4
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Fubarable & Zack

    thannnnnnnks .. it is useful linkes !


    Is the solution in the first sentence like that :


    private Map<Integer, String> hotelMap;

  5. #5
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Yes, that'll work.

  6. #6
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by sweet girl View Post
    hi ..


    - how can I write constructor that initializes the class to an empty map ??
    Java Code:
    public HotelCatalogue()
    {
    
    hotelMap = new HashMap<Integer, String>();
    - how can I Write an instance method for some class that takes no arguments, and returns no value.

    the method should simply enter the four entries

    Java Code:
    public void addHotel()
    {
    
    hotelMap.put(101, “RadisonSas”)
    hotelMap.put(103, “ForSeason”)
    hotelMap.put(105, “Hayat Regency”)
    hotelMap.put(107, “Concord al-Salam”)
    }


    is it correct ???

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Looks OK to me -- when you get it to compile :) Semi-colons will help that. In fact, before asking us, why not try to compile it first? Also, have you written the constructor and constructed the HashMap in it?

  8. #8
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Looks OK to me -- when you get it to compile :) Semi-colons will help that.


    I guess that I forgot Semi-colons :D



    In fact, before asking us, why not try to compile it first?

    cause I don't know how to use BlueJ program very wello

    Also, have you written the constructor and constructed the HashMap in it?

    yesss I wrote the constructor HotelCatalogue that doesn't take argument and gives the initial value for the attribute hotelMap << an empty map


  9. #9
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    ummmmmmmmmm sory but I have an important questiono


    What is really the main difference between map collections and other collections ??:confused::confused:

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Think of a Map like an English-Spanish dictionary where you use the English word to look up its Spanish equivalent. Here the English word is the key -- that which is used to look something up, and the Spanish word is the value -- that which is returned or found from the look up. Most other collections such as LinkedList, ArrayList and Set don't have two objects, the keys and values, but only one object, and sometimes a numeric index.

  11. #11
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    It is clear now :):)

    Thank you so much

    Regards :o

  12. #12
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    sorry but I have another question that asking to give an example for :






    my answer :














    is it correct ?
    Last edited by sweet girl; 12-09-2010 at 09:19 AM.

  13. #13
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    :confused:

    :(
    :confused:

  14. #14
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Is there an error, what exactly is your question :confused:

  15. #15
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    Is there an error, what exactly is your question :confused:
    I'm ask .. is my solution (the examples) for these code are correct ??

  16. #16
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Looks ok to me

  17. #17
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    2 - 3 -5 correct ?

    How can I solve 6 & 7


    :$

  18. #18
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    can you be more specific about 6 & 7 just finding it hard to understand what you are looking for especially "Message expression".

  19. #19
    sweet girl's Avatar
    sweet girl is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Default

    Java Code:
    
        public void setYearsModel(int yearsModel) 
        {  this.yearsModel = yearsModel;      }
    }
    is this a Message expression ?


    the accessor method :


    Java Code:
       public int getYearsModel() 
        {  return yearsModel;  }
    :confused:

  20. #20
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 12
    Last Post: 07-27-2010, 10:40 AM
  2. Replies: 2
    Last Post: 02-01-2010, 06:45 PM
  3. Replies: 3
    Last Post: 11-02-2008, 02:29 AM
  4. quickly IDE
    By tascoa in forum New To Java
    Replies: 1
    Last Post: 10-16-2008, 03:37 PM
  5. passively and quickly capturing request/response
    By sideswipe091976 in forum Networking
    Replies: 1
    Last Post: 07-10-2008, 02:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •