#Java Class Writing

1 messages · Page 1 of 1 (latest)

wintry agate
#

Hello, I have an assignment on Java class writing and to me the codelooks fine but I have errors. I realize it is likely something really simple to fix, but as a beginner I'm not great at spotting and then fixing the issues. If someone would be able to take a look and walk me through how to fix it, that would be wonderful.

unique tinselBOT
#

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

hot estuary
#

you are using variables which do not exist

#

age = a; what is a?

minor carbon
#

same with n and out. etc

polar hearth
#

where is a?

minor carbon
#

I suggest to read the errors

wintry agate
#

I was trying to write it as age = a so I could use a as a keyword

minor carbon
#

a doesnt exist

hot estuary
#

a does not exist

wintry agate
hot estuary
polar hearth
#

i would suggest going like

#

this.age = age

#

but im not sure if that really works

#

java newbie attempting to help someone with java should be a sitcom

hot estuary
#

that is, in fact, how you resolve name conflicts

wintry agate
polar hearth
#

that was just a guess:0

#

i had not read the code thoroughly

wintry agate
polar hearth
#

now i need someone to help with my project

#

alright imma play a game ig

hot estuary
#

also, out does not exist

wintry agate
hot estuary
#

again

#

you are calling methods that do not exist

wintry agate
#

Well I wrote mOne = new Monster and am trying to call mOne did I not declare it right?

hot estuary
#

mOne.isBigger(mTwo)

#

what is isBigger?

wintry agate
#

Trying to ask is Monster One bigger than Monster two

hot estuary
#

so how is it should be determined?

#

and, more importantly, how is Java supposed to know that?

wintry agate
#

Ah, taking a guess here, but the "isBigger" isn't declared anywhere else. Is that my issue here?

hot estuary
#

have you learned methods in your class?

wintry agate
#

Code that only runs when called

hot estuary
#

that's a weird way to put it

#

all code only runs when it's called

wintry agate
#

It's meant to perform a specific task (but then again all code is)

hot estuary
#

but you're supposed to create methods in your class that compare the size of a monster that the method is called on, to the size of the monster that's passed as an argument

#

same with name

#

(also, dunno why you named the field age instead of size)

wintry agate
#

Do I need to add a boolean for checking if the names are the same?

hot estuary
#

you need to make two methods that return a boolean value

#

if the statement above confuses you, you should re-examine your study materials, since you've said that you already learned methods

wintry agate
#

I think I got it to work

#

Thank you so much for your help

polar hearth