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
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...
Related Q & A:
- How do I change the value of an attribute?Best solution by Stack Overflow
- How do I change the cursor from a blinking black block to a blinking line?Best solution by Server Fault
- On photobucket how can I change the background of a picture?Best solution by Yahoo! Answers
- How do you change the name on a primary user?
- How do you change your avatar from a girl to a boy?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.