#classes and instances help needed quick question

1 messages · Page 1 of 1 (latest)

blazing shuttleBOT
#

<@&987246399047479336> please have a look, thanks.

blazing shuttleBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

versed maple
#

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

delicate ruin
#

oh

#

sugh

#

sigh

#

now it says this

versed maple
#

is the field private?

delicate ruin
#

do i just make the condition

#

public

versed maple
#

oh do you have getters and setters?

delicate ruin
#

yes

versed maple
#

use getter to get values and setter to set values

versed maple
delicate ruin
#

would i just do x.getCondition

versed maple
#

so that it can't be modified by anyone else

delicate ruin
versed maple
#

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

delicate ruin
#

to change the condtion in the Card class

#

so do i have to make the condition var public

versed maple
#

if you wanna use it in other class, you use getters and setters

#

since those are public

delicate ruin
#

i want to change its value from another calss

#

class

versed maple
#

that's cool

#

i don't see the problem

delicate ruin
#

so to change the value

#

i dont need to change it to public?

#

here

versed maple
#

i don't think you read my texts carefully, getters and setters are used to access and modify these vars anywhere you want to

delicate ruin
#

oh

versed maple
#

since these are public and can be used

delicate ruin
#

the setter can be used from another class?

versed maple
#

yes

delicate ruin
versed maple
#

are you using intellij?

#

or is it vscode

delicate ruin
#

i think i did it

versed maple
#

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

delicate ruin
#

lmao

#

whoops

#

another question

#

i need help returning here

versed maple
#

what's the problem?

delicate ruin
#

this is what is retunred

versed maple
#

hmm you may need to generate a toString method for your class

delicate ruin
#

i do what that

versed maple
#

checkout by right clicking inside your card class

#

right did you already have it

delicate ruin
#

but that returns a string to the method

#

i need to return a card object

versed maple
#

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

delicate ruin
#

so it should return the memory location?

versed maple
#

it should return a card object which it did

delicate ruin
#

hmm little odd

#

but ig its right

versed maple
#

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

delicate ruin
#

ok

#

why does this not print the whole string

#

using

versed maple
#

idk it works for me

#

output

#

so ye you don't need toString

delicate ruin
#

its in 2 diffent classe

versed maple
#

sysout automatically takes care of that

versed maple
delicate ruin
#

like the Card

#

and collection are 2 diffrent

versed maple
#

not sure exactly, seems alright to me, may have to use annotation override on top

delicate ruin
#

where wld i fix that

versed maple
#

on top of your toString() method use annotation override

blazing shuttleBOT
#

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 👍