9/13


#1

Please help..this is my code! it is giving me an error saying to put the semi-colon instead of the dot at "Dog spike.bark"
class Dog {

int age;

public Dog(int dogsAge) {
age = dogsAge;

}

public void bark() {

System.out.println("Woof!");

}

public static void main(String[] args) {

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

}


#2

$ javac Dog.java 
Dog.java:17: error: ';' expected
Dog spike.bark(); 
         ^
1 error

It (the compiler) is not saying that you should put a semi-colon there, it can't tell you what your code should say, it doesn't know what you mean to describe.

It's saying that, based on what it had read so far, or to make some sort of sense out of that line, a semi-colon would be required there.

You will need to reconsider what you meant to do there and find out how to write that.

I suggest reading the line and seeing if you can motivate why each part needs to be there. You should not be able to, because that line isn't valid syntax. If you "can" motivate what each thing in it does, then you have misunderstood something - explaining what you think it does makes it possible for others to point out where in the reasoning you went wrong.


#3

correct answer is

spike.bark();


#4

That's what I put in but I'm still getting the error "Did you call the bark method on the spike object? Make sure you call it inside of the main method."


#5

Yhep, im getting the same mistake..

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

}

public void bark(){
System.out.println("Woof");
}

public static void main(String[] args) {

    Dog spike = new Dog(21);
spike.bark();


}

}

and it keeps telling me to make sure that the bark method is inside the main method ...
i feel like is something very very simple im not seeing... :frowning:


#6

same error here, anyone can tell what is wrong?

class Dog {
int age;
public Dog(int dogsAge){
age=dogsAge;
}
public void bark(){
System.out.println("Woof");
}
public static void main(String[] args) {
Dog spike = new Dog(5);
spike.bark();
}
}


#7

I found the real problem, in the method it must say Woof! with an exclamation


#8

The majority of the issue is to close each public method.
ex:
public dog()
{
}
public void cat
{
}

examples of not closing it which causes errors
public bark()
{
public void Dog(int age)
{
}
} <----- Make sure to close it before the next public method.


#9

kudos megacoder thanks man! typical homer simpson 'doh' ! for me.


#10

Thanks @teracoder50388 it works now
What does exclamation has to do with it, can anyone explain it to me?


#11

It don't do anything by itself, but when you upload the exercise it checks the prints to verify that you done everything ok and the "desired output" is the one with the exclamation. The code can be ok but if you print anything else but the desired output it will be wrong


#12

I did that already and still giving me an error

class Dog {

int age;

public Dog(int dogsAge) { 

age = dogsAge;

public void bark() {

System.out.println("Woof!");

}

public static void main(String[] args) {

Dog spike = new Dog(3);
spike.bark();

}

}


#13

I'm getting the same error message.

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

age = dogsAge;

}
public void bark() {
System.out.println("Woof!");
}

public static void main(String[] args) {

	Dog spike = new Dog(5);

spike.bark();

}


#14

u need to close another bracket

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

age = dogsAge;

}
public void bark() {
System.out.println("Woof!");
}

public static void main(String[] args) {

	Dog spike = new Dog(5);

spike.bark();
}
}

#15

This is the final working code thank u everyone

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

age = dogsAge;

}
public void bark() {
System.out.println("Woof!");
}

public static void main(String[] args) {

	Dog spike = new Dog(5);

spike.bark();
}
}

#16

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