Learn Java Help at 65% 10. Methods ||


#1

This is my code:
(Go down for more info)
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);

}

}
}

The code for some reason works in the editor but in the box it is incorrect.
Please help.
Instructions below

Fantastic! Similar to constructors, you can customize methods to accept parameters.

class Car {

int modelYear;

public Car(int year) {

    modelYear = year;

}

public void startEngine() {
    System.out.println("Vroom!");
}

public void drive(int distanceInMiles) {

    System.out.println("Miles driven: " + distanceInMiles);

}

public static void main(String[] args){

    Car myFastCar = new Car(2007);
    myFastCar.startEngine();
    myFastCar.drive(1628);

}

In the example above, we create a drive method that accepts an int parameter called distanceInMiles. In the main method, we call the drive method on the myFastCar object and provide an int parameter of 1628.

Calling the drive method on myFastCar will result in printing Miles driven: 1628 to the console.
Instructions
1.
In between the bark and main methods, add a method called run to the Dog class by typing:


#2

You have to do one step at a time and then press Run to get your checkmark. You can't go ahead and do all of the steps in one go.


#3

I have done that before with angular, sql, javascript, and the beginning of this and it worked just fine.


#4

i did it that way but it did´t work. plis help i need to continue to the next exersices!!!


#5

You can try these steps:

  • reload/refresh the browser
  • use the "I want to restart this exercise" to clear it all out and start fresh

If you do restart, and Step 1 doesn't work, come back and post a screenshot.