I am trying to figure out how to get information back from a different method.
Basically I want to write a program to create a car, but I want to be able to add features based on user our put (V6 versus V8, Color choice, etc), but I want each one to be broken out into their own method but I am unsure of how to call from the main method and return the variable (engineSize = V8, color = blue, etc). Can someone point me in the right direction (and pardon my noobness if I got the terminology wrong).
It would be helpful if you could post the code that you've come up with so far, so we can see if you're on the right track. It would also help a great deal in providing more conrete suggestions that will help you along.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
posted 5 years ago
I have actually not started coding it yet.... well other than notes I am taking a project and turning it into a learning opportunity. The project I have right now just says choose a car (1,2,3) and then outputs the actual name of the car. Now I want to take it a step further and add in options which would be in there own method.
Okay so I threw together some quick code so you can visually see what I am trying to do (this is not complete by any means). I am just trying to get to the point where I can return the users feedback to the main body so it will be able to print out the choices they make.
Also this may not be the best way to do something but I am trying to teach myself some different parts of java programming by taking a project that I know what I want it to do and then create a program around the part of java I want to learn (in this case using multiple methods and returning the user input).
You are using the Scanner object incorrectly. Here is a quick tutorial.
You might want to read up on methods and parameters. Here is a tutorial from Oracle.
It doesn't mean main(String args) has a String, you put String in every method parameter.
For user-defined methods, the things inside parenthesis (known as parameters) are optional and you only define them if the method needs it.
Help first. Criticize second.
posted 5 years ago
Thank you, both answers put me on the right path.
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop