Exercise 10 Methods says error "Did you create the run method? Place it between the bark and main method." and won't let me pass


#1

Error message blocks proceeding with the exercise, however the code works correctly.
Link to the exercise:

The following error message appears after clicking Run button:
"Did you create the run method? Place it between the bark and main method."

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(5);
    spike.bark();
    spike.run(40);


	}

}

#2

For whatever reason there's a whole lot of pattern matching going on in that track. Never mind whether the code meets what's asked for. The pattern you're looking to match is:

/[Oo][Oo][Ff]\s*!?\s*"\s*\)\s*;\s*\}\s*public\s+void\s+run\(\s*\)\s*\{\s*\}\s*public\s+static/

You can paste in the pattern and your code at https://regex101.com/ to investigate where it isn't matching

You might start by fixing your formatting though, your code should be more tidy than what you have there.


#3

I am having the same issue as the above poster, and even after clicking the "get code" button the code isn't working.


#4

Hi Jonatan, thank you so much for quick answer.
However I am afraid that I not fully understand it. You are saying about formatting, however it works correctly in the previous steps, so when I have added two additional rows of code, how could it affect its work? More over, the error message is displayed even after clicking Get Code button.
I compared my code with the example from the exercise, it looks similar.

Thanks in advance,
Olga


#5

Hi, I have bypassed the issue by the following steps:
A. Delete code rows which were added in this step (10/13)
B. Follow the instructions in the Step 1 and click Run button
C. Follow the instructions in the Step 2 and click Run button
and so on
Proceed to the last step and click Run after completing each step.

Hope this will help.

(The reason of my issue was that I clicked Run button after completing all the steps, not one by one)

Regards,
Olga


#6

Oh, thank you so much!!
I did it and it worked!


#7

Very helpful thanks!


#8

Olga,

What added code rows do you mean in "A", the ones the provide you when you ask for the code? It is not working for me.

Cheers,


#9

Hi,

I deleted the code previously added by myself on this page (the 10th page from 13). Then began to execute steps from Step 1 till 4 one by one not forgetting to click on Run button after each step.

Regards,
Olga


#10

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