Java OOP - 11. Using Methods II


#1


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);

    
	}
}


#2

Having the same issue, not able to progress


#3

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/


#4

Is there anyway I can fix this?


#5

Is there anyway I can fix this error?


#6

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