Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Use HashMap to Call Methods

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Use HashMap to Call Methods

    Hi Guys, Need help with an Assignment.

    I need to create a HashMap, then use it to be able to call methods.
    For example:

    //Maps Key words to responses
    private HashMap<String, String> mapResponder;

    //Constructor
    mapResponder = new HashMap<String, String>();
    fillResponseMap();

    /**
    * List of the responders
    */
    private void fillResponseMap()
    {
    mapResponder.put ("cold",
    "I WANT TO LINK THIS TO A METHOD");
    mapResponder.put ("circle",
    "I WANT TO LINK THIS TO CALL A METHOD");
    }


  2. #2
    Administrator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,848
    Thanks
    64
    Thanked 2,645 Times in 2,615 Posts

    Default Re: Use HashMap to Call Methods

    Please explain what "LINK THIS TO A METHOD" means?
    What will the method do? How will it be called?
    If the value put in the HashMap is an instance of a class, that object could be of a class with a method that can be called.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Use HashMap to Call Methods

    I have a program that when you type in the terminal window, for example the word "Circle" , then a circle will appear. Now I have been asked to improve the program so I can get the circle to move left or right by typing the word "circle left" or "circle right".

    They have asked me to create a HashMap to store keys so I can call method from it.

    See this thread about my assignment
    Click Here#post85834

    See I thought Maybe I could create methods such as MoveCircle left (Which will make the circle move left) so when I type it in the terminal and recognized to word left will then move the circle left...

    Thanks

Similar Threads

  1. Call by Reference & Call by Value
    By Lokesh in forum Java Theory & Questions
    Replies: 3
    Last Post: January 21st, 2013, 01:03 PM
  2. HashMap to Call a Method
    By AbarthGT in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 10th, 2012, 01:30 PM
  3. buttons that call methods
    By coley909 in forum What's Wrong With My Code?
    Replies: 37
    Last Post: November 28th, 2012, 08:15 AM
  4. call by value and call by reference
    By Appu14 in forum The Cafe
    Replies: 1
    Last Post: September 2nd, 2012, 07:58 AM
  5. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 02:16 AM