Java OOP - 11. Using Methods II

<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.>

Everytime I run my code, I keep getting an error saying “Did you type the command correctly?” for “System.out.println(spikeAge);” in the main class. Is this a problem with the website, or am I doing something wrong?

```

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

spike.bark();
spike.run(24);


}

}

<do not remove the three backticks above>

Having the same issue, not able to progress

There are a whole bunch of regexes in the checkpoints in the java track, pretty poor design if you ask me.

This is the regex that you need to match:

/getAge\s*\(\s*\)\s*;\s*System\.out\.println\(\s*spikeAge\s*\)\s*;\s*\}/

regex crash course (enough to read the above anyway)
\s is whitespace

  • means zero or more matches of the thing that comes before it
    \. is just a dot/period

Here’s a useful site for testing if your text matches a regex pattern: https://regex101.com/

Is there anyway I can fix this?

Is there anyway I can fix this error?

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