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.

0 Answers0