#Java Input for Objects
26 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @cerulean canyon! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Normally I'd say however you want. And yet, you should probably avoid protocols and user inputs inside constructors
you could first demand the user enters the needed input into some variables, and then once that's done, you can build the object with these variables
What about the UML diagram?
Doesn’t it show that the variables need to be in the constructor?
@thick pike
You're allowed to have other variables. Exclusivity isn't all that important in programming
so make a main class?
Or anything else you see fit, just, probably not in the constructor
it doesnt seem i can have the inputs outside the constructor
Honestly not sure what you mean
i tried having the variables outside the constructor and it doesn't look it goes well
So. As I said. In addition to the variables you have in the class and the constructor, you're allowed to have other variables too
So, first go back to what you had initially
Then. When you want to have variables to store user input, it doesn't need to be these variables. You can have other variables, these other ones won't be in the constructor, nor even in this class
And using these other variables, you'll call the constructor, to transmit the value to that class
like this @thick pike ?
toString()? How would that relate
Okay, for now on, you'll make as if this class doesn't exist
Now you'll make a method, elsewhere, that asks the user to input 3 things: A name, a price and an amount
toString() or the whole class
I meant the whole class