Using methods II, exercise 11


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/using-methods-2?action=lesson_resume
<In what way does your code behave incorrectly? Include ALL error messages.>
The program keeps asking me: “Did you type the command correctly?” Obviously not, but I do not see why…
Help me please if you see an error.

```

class Dog {
int age;
public Dog(int dogsAge) {
age = dogsAge;
}
public void bark() {
System.out.println(“Woof!”);
}
public void run(int feet) {
System.out.println(“Your dog ran " + feet + " feet!”);
}

public int getAge() {
return age;
}

public static void main(String[] args) {
	Dog spike = new Dog(5);

int spikeAge = spike.getAge();
System.out.println(spikeAge);

spike.bark();
spike.run(789);
}

}

<do not remove the three backticks above>

#2

Try moving two methods above getAge() and the print.

class Dog {
  int age;
  public Dog(int dogsAge) {
    age = dogsAge;
  }

  public void bark() {
    System.out.println("Woof!");
  }

  public void run(int feet) {
    System.out.println("Your dog ran " + feet + " feet!");
  }
  
  public int getAge() {
    return age;
  }
  
  public static void main(String[] args) {
  	Dog spike = new Dog(5);
    spike.bark();
    spike.run(789);
    int spikeAge = spike.getAge();
    System.out.println(spikeAge);
  }
}

#3

Thank you, it works. What puzzles me now is whether it would be a problem in eg Eclipse, or is it just a codecademy issue?


#4

I think it’s just a codecademy issue. Code should run fine the way you had it.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.