0

Given two objects (two characters), I want to take the users string and convert it to a format where I can call methods upon it.

For instance, james.boilWater(10), will call the boilWater method for the object james. I am struggling to work out how to call the method on one of the characters given a string.

And no, using lots of if/else will just be inefficient if I have hundreds of characters.

    CartoonFigure james = new CartoonFigure("Guy1", 50, 50);
    CartoonFigure bob = new CartoonFigure("girl3", 200, 200);

    String charName = UI.askString("What character do you want");

    charName.boilWater(10);

I am using the ecs100 library by the way, but the same concept should apply to command line applications.

3
  • Also see stackoverflow.com/q/20974558/3973077 Commented Mar 28, 2016 at 23:31
  • Why do you write "Guy1" and "girl3" instead of "james" and "bob"? Commented Mar 28, 2016 at 23:34
  • those are just the names of the images (which are shown on the screen), in this case guy1.jpg and girl3.jpg. Commented Mar 28, 2016 at 23:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.