Methods 12/13 checkStatus code won't work


#1

Idk why this won't work I've been trying over and over

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) {
    spike.checkStatus
    Dog spike = new Dog(5);
    spike.bark();
    spike.run(40);
    int spikeAge = spike.getAge();
    System.out.println(spikeAge);

    }

}


#2

Hey.

When calling a method you need to call them with an opening and closing parenthesis on the end. Just like your other method calls.

Also, you can only refer to the spike object after it has been created. So you'll also have to move it (the checkStatus method) further down the scope.

spike.checkStatus should look like:

spike.checkStatus();

#3

Is this correct?
class Dog {
class Dog extends Animal {

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(40);
int spikeAge = spike.getAge();
System.out.println(spikeAge);

spike.checkStatus();
}

}


#4

From what I can tell, almost.

You have two Dog classes. You should only have the one that extends Animal.


#5

Thank you so much I was looking for how to fix this all day


#6

Still spike.checkStatus() is not working.
Its showing Did you call the checkStatus method inside of main?

What should i probably do??


#7

Some of the Java stuff can be quite buggy..

Would you mind either taking a screenshot of the problem or pasting the code for us to have a look at?


#8


#9

What I would try (copy all the code first) is on the bottom right, click > Get Help. Then in the menu "I want to restart this exercise". Paste the code back into editor and see what happens.

If not here's my code for you to have a look at/ try.

class Dog extends Animal{
  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(1);

    spike.bark();
    spike.run(2);

    int spikeAge = spike.getAge();

    System.out.println(spikeAge);

    spike.checkStatus();
  }
}

#10

yup it worked!!
Thanks a lot for your time!!


#11

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