#classes and instances help needed quick question
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
is x declared somewhere?
so x is of type Card
can i see Card class
wait i see a typo, x.condtion instead of x.condition
is the field private?
oh do you have getters and setters?
yes
use getter to get values and setter to set values
and no, ideally you wanna have vars as private
how would i use this
would i just do x.getCondition
so that it can't be modified by anyone else
makes sense
x.getCondition()
for ex: even if someone uses your setters to modify a value, you could put a check inside your setters like "check for negative value" only then you allow someone to set value
that's just one way to understand
yea so i need to do something in the other Class
to change the condtion in the Card class
so do i have to make the condition var public
if you wanna use it in other class, you use getters and setters
since those are public
i don't think you read my texts carefully, getters and setters are used to access and modify these vars anywhere you want to
oh
since these are public and can be used
the setter can be used from another class?
yes
so im just confused how i would make the setter
yes
btw you can generate getters and setters via IDE
i think it's right click inside class-->generate-->getters and setters
then you select your vars
wait not here, inside Card class
nvm it looked like you did it in another class
it is in card calss
lmao
whoops
another question
i need help returning here
what's the problem?
this is what is retunred
hmm you may need to generate a toString method for your class
i do what that
yea then it only needs to be return oldCard
and just print it inside the sysout
you handled return types like it was supposed to be so no problem there
so it should return the memory location?
it should return a card object which it did
your printing the object ig that's why you are confused, have you tried doing System.out.printf("sold: %s\n", binder[index].getPokemonname())
or if you want all the details fo card then prolly toString method inside sysout
altho i remember reading somewhere that sysout automatically uses toString() method to print out on console but weird dk much about printf
its in 2 diffent classe
sysout automatically takes care of that
wym?
not sure exactly, seems alright to me, may have to use annotation override on top
where wld i fix that
on top of your toString() method use annotation override
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍