How can I get the value of dynamically created input?

How do you change the value of a get/set method with user input?

  • Variables: Length, height Methods: setLength – changes the base. Requires one parameter for the length setHeight – changes the height. Requires one parameter for the height getLength – returns the triangle base getHeight – returns the triangle height I'm still not understanding the whole method concept and now I have to do this! I need it with user input, so I can't do (9,10) or (3,2) or something. I also have to output the current values until I want to quit the program.

  • Answer:

    Here's some pseudocode to illustrate get/set methods using user input. main() { Prompt for Length userInput = .... setLength(userInput); Print (getLength); } setLength(int newLength) { length = newLength; } getLength() { return length; } You can do something similar for the width. Hopefully that gives you an idea of how it works! (If not, feel free to edit your question. I'll keep an eye on it!) Separate classes: (I'm going to slip into Java here, since I'm thinking that may be what you're using) Say you have class Main and class Triangle. In your main, make a Triangle object: Triangle myTriangle = new Triangle(/* Params here*/); To access methods for the Triangle, do this: myTriangle.<methodName>; For instance: myTriangle.setLength(9); Or: myTriangle.setLength(userLength); Where userLength is a user input.

Kornfan71 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Here's some pseudocode to illustrate get/set methods using user input. main() { Prompt for Length userInput = .... setLength(userInput); Print (getLength); } setLength(int newLength) { length = newLength; } getLength() { return length; } You can do something similar for the width. Hopefully that gives you an idea of how it works! (If not, feel free to edit your question. I'll keep an eye on it!) Separate classes: (I'm going to slip into Java here, since I'm thinking that may be what you're using) Say you have class Main and class Triangle. In your main, make a Triangle object: Triangle myTriangle = new Triangle(/* Params here*/); To access methods for the Triangle, do this: myTriangle.<methodName>; For instance: myTriangle.setLength(9); Or: myTriangle.setLength(userLength); Where userLength is a user input.

Kornfan7...

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.