10. Methods II


#1



The window is showing my code printing correctly, but I am still receiving the error: "Did you create the run method? Place it in between bark and main method." What am I missing?


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 static void main(String[] args) {

Dog spike = new Dog(7);
 spike.bark();
  spike.run(5);
}
}


#2

Did you do the next step before passing the current one? May need to undo that.


#3

I'm having the exact same problem right now
the console even outputs the correct thing, so I don't know what's wrong here


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


	public static void main(String[] args) {
    Dog spike = new Dog(5);
    spike.bark();
    spike.run(69);
	}

  public void bark(){
    System.out.println("Woof!");
  }
  
    public void run(int feet) {
    System.out.println("Your dog ran " + feet + " feet!");
  }  

}

#4

Update: I have a solution

Click "Get Help" then click on "I want to restart this excersise"
Then do it step by step, and make sure the run method is between bark and main

for some reason it doesn't work unless you hit run for every single step


#5

Thanks man that helped!


#6

Thanks guy it's worked!


#7

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