Results 1 to 10 of 10
  1. #1
    wildcardcrow is offline Member
    Join Date
    Apr 2014
    Posts
    13
    Rep Power
    0

    Default trying to create a hash map

    hi guys me again, i will be grateful for any assistance you can give;
    i am trying to create a class (DVD) with an instance variable that references a map,
    the constructor for this class must create an empty map and assign it to the instance variable map.
    i want to populate this map with instances of a different class called tv series,
    i am using blueJ,
    i am not sure why this doesn't work
    Java Code:
    import java.util.*;
    /**
     * Write a description of class Season here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class DVD
    {
       public static Map<String, TvSeries>DVD;
       public TvSeries program;
    
       /**
        * Constructor for objects of class Season
        */
       public Map<String, TvSeries>DVD() 
       {
          DVD = new HashMap<String,TvSeries>();
          // initialise instance variables
          
          return new HashMap<>();
       }
    Last edited by wildcardcrow; 05-05-2014 at 05:20 PM.

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

    Default Re: trying to create a hash map

    this doesn't work
    Please explain. Copy the text of any error messages and paste it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: trying to create a hash map

    Well, one thing is that constructors don't have return values.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    wildcardcrow is offline Member
    Join Date
    Apr 2014
    Posts
    13
    Rep Power
    0

    Default Re: trying to create a hash map

    the code compiles, it doesnt tie in my other class, the constructor will create a new dvd -
    Java Code:
    dvd 1 = new dvd();
    gives the following

    Compilation failed (05/05/2014 15:25:09)
    Error: line 1 - not a statement
    Error: line 1 - ';' expected

  5. #5
    wildcardcrow is offline Member
    Join Date
    Apr 2014
    Posts
    13
    Rep Power
    0

    Default Re: trying to create a hash map

    i know constructors dont return values, however i am trying everything

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: trying to create a hash map

    The int value: 1 is not a valid variable name.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: trying to create a hash map

    I think I misread your code due to formatting. Anyway, A variable in Java may not start with a number. And Java is case sensitive so dvd() and DVD() are different.

    Just create the Hashmap in your main method and try adding some programs there for practice

    Java Code:
    Map<String, String> myMap = new HashMap<>();
    
    myMap.put("Name", "<your name here>");
    System.out.println(myMap.get("Name"));
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    wildcardcrow is offline Member
    Join Date
    Apr 2014
    Posts
    13
    Rep Power
    0

    Default Re: trying to create a hash map

    sorry for my grammatical errors, the 1 was incidental i had been using letters to try this, but they also were not working,

  9. #9
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    1

    Default Re: trying to create a hash map

    Could you post the code that has the errors and the exact error messages please? We can only look at the code you show us and that showed 2 errors:
    1) constructor should simply be defined as "public DVD()" without the Map<...> part
    2) the variable name cannot be a number
    If you encounter more or other problems you should show us the code and the details.

    Konrad

  10. #10
    wildcardcrow is offline Member
    Join Date
    Apr 2014
    Posts
    13
    Rep Power
    0

    Default Re: trying to create a hash map

    cheers konrad, i like you guys as you are a great sounding board, i am using blueJ to compile, which when it doesn't compile, highlights the specific code with the problem gives great advice like .getTime() not a class, i resolved this problem(the one above) but thanks for your input and support

Similar Threads

  1. Hash
    By CodeX Pro in forum New To Java
    Replies: 7
    Last Post: 06-07-2013, 06:32 PM
  2. Replies: 9
    Last Post: 11-12-2012, 12:38 PM
  3. Hash set
    By lakshmibvaraprasad in forum New To Java
    Replies: 2
    Last Post: 07-20-2011, 07:58 PM
  4. Hash
    By sandy1028 in forum New To Java
    Replies: 4
    Last Post: 04-17-2009, 11:36 AM
  5. Hash Map
    By rekha in forum New To Java
    Replies: 1
    Last Post: 03-21-2009, 02:00 PM

Posting Permissions

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