Results 1 to 5 of 5
  1. #1
    mcnikal is offline Member
    Join Date
    Mar 2014
    Posts
    13
    Rep Power
    0

    Default Creating instance variables and constructors for a map class

    Hello,

    I have to create an application that deals with maps.

    The scenario is quite simple but I'm struggling to get going.

    I first have to create the instance variables for the class.

    So very simply if my hashmap is going to consist of football clubs and players. Football clubs being a string value for the key and players being a set of strings for the values. How would I go about creating the instance variable in a class for this?

    Alternatively if anybody has a resource that outlines this in better detail that would be great, I can't seem to find anything that specifically deals with instance variables and constructors for maps.

    Thanks

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: Creating instance variables and constructors for a map class

    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mcnikal is offline Member
    Join Date
    Mar 2014
    Posts
    13
    Rep Power
    0

    Default Re: Creating instance variables and constructors for a map class

    Hello,

    I have a basic understanding of constructors and instance variables, but so far my experience is only with strings, integers and objects I've constructed myself. My problem with this scenario is the maps, its the first part of my learning where I've hit a bit of a brick wall.

    Thanks

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default Re: Creating instance variables and constructors for a map class

    Start with the API doc for Map and follow a link there to Collections Framework.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    mcnikal is offline Member
    Join Date
    Mar 2014
    Posts
    13
    Rep Power
    0

    Default Re: Creating instance variables and constructors for a map class

    Hello,

    I'v made an attempt at creating an instance variable and a constructor in my class. However I'm not sure I've done it correctly. It compiles without any errors but I don't know how to then create a new instance of my class in the workspace loaded with the correct arguments.

    Java Code:
    public class FootballClub
    {
        // instance variables - replace the example below with your own
        private HashMap <String, Set<String>> footballClub;
        private HashSet<String> player;
    
        /**
         * Constructor for objects of class FootballClub
         */
        public FootballClub(HashMap <String, Set<String>> footballClubMap, HashSet <String>
         playerNameSet)
        {
            // initialise instance variables
            this.footballClub = footballClubMap;
            this.player = playerNameSet;
            
        }
    Last edited by mcnikal; 03-28-2014 at 10:38 AM.

Similar Threads

  1. Error - creating an instance of an inner class
    By Zarah in forum New To Java
    Replies: 6
    Last Post: 03-24-2014, 06:54 AM
  2. Replies: 2
    Last Post: 09-16-2013, 05:19 PM
  3. Replies: 4
    Last Post: 08-26-2012, 02:09 AM
  4. Replies: 1
    Last Post: 04-21-2012, 07:03 PM
  5. Help with creating an instance of a class extension
    By Inferno719 in forum New To Java
    Replies: 19
    Last Post: 05-04-2011, 04:53 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
  •