I tried to put "3" as dog's age, but it doesn't work. Don't know why


#1

I tried to put "3" as dog's age, but it doesn't work. Don't know why.

So, I clicked Get code, and got answer 5. WHY?

Is there anyone can explain why? I am very beginner of this Java code..

Thank you~


Java OOP - 7.Objects
#2

please post your code


#3

public static void main(String[] args) {

Dog Spike = new Dogs (5)

Wrong answer: Dog Spike = new Dogs (n)

Right answer: Dog Spike = new Dogs (5) Why it is 5?


#4

5 is an arbitrary number, so perhaps something, like the instructions, is saying that 5 is the desired value. If you want it to be 3, then 5 wouldn't be the number to use.

If you're using n before having defined n, then you've created something that is impossible to execute, so it won't.


#5

You forgot ';' after (5) ?


#6

Maybe because you used the space bar?
Not: new Dog (5);
But: new Dog(3);


#7

It's not a problem with the age, its that you capitalized the name Spike when it wants spike, so this should work. I was having the same problem until i realised the Capitalization thing changed when I clicked get code.

Dog spike = new Dog(3);


#8

to luvinliiph yes you are right Capitalizastion is important in programming.

to devsolver76125 No spacebar isnt important. every whitespace is ignored by the IDE


#9

thanks for the reply


#10

Thanks for the answer, I've tried it a lot of times.


#11

Funny, the built-in IDE didn't accept my Dog spike = new Dog (2); because of the space between Dog and (2)...

I only got it right after removing the space there.


#12

possible but shouldn't. The problem might have been the 'checker' Codecademy is trying to check if you've written the right things so if they aren't accepting new Dog (2) then u have to remove the space. But a common IDE shouldn't care idk didn't tested that.

Greetz
Stoffel


#13

Yeah, you're probably right...
Cheers!