Dog.java


#1

Was experiencing with the coding once again and I tried to redo the everything I did but the code didn't refresh (Even after I erased my browser history). So I started over and thinking to myself "Eventually this going to work" but life isn't like, at least not this time. I would also like to know if the coding format/style i've written is good (Just in case I should try writing it differently so it's easier to understand) and can someone elaborate on the errors so i'm able to find the solutions on my own.

//Class - Describes the instructions for the data 		structure. Ex. || class Dog
//Method - Is a pre-defined set of instructions to define action within a class
class Dog {

//Instance Variable - Specific details that will be used      in the class Ex. || int Dog
  int Dog; 

//Constructor - Allows the user to create instances     			within the class. Ex. || public Dog
//Parameters - Allows data types to be created with specified attributes. Ex. || (int dogsAge)
//Constructor block - Space within { } 
  public Dog(int dogsAge) {
    age=dogsAge;
  }
  
   public void bark() {
     System.out.prntln("Woof!");
   } 

//Java default main method 
//Object - Is the instance of a class Ex. || Dog \\\   		Ex. Dog spike = Dog(12);
   public static void main(String [] args) {
    Dog spike = Dog(12);  
    Dog.bark(); 
  }
    

}

Errors

Dog.java:12: error: cannot find symbol
    age=dogsAge;
    ^
  symbol:   variable age
  location: class Dog
Dog.java:16: error: cannot find symbol
     System.out.prntln("Woof!");
               ^
  symbol:   method prntln(String)
  location: variable out of type PrintStream
Dog.java:21: error: cannot find symbol
    Dog spike = Dog(12);  
                ^
  symbol:   method Dog(int)
  location: class Dog
Dog.java:22: error: non-static variable Dog cannot be referenced from a static context
    Dog.bark(); 
    ^
Dog.java:22: error: int cannot be dereferenced
    Dog.bark(); 
       ^
5 errors

I need help on 6/13 oop
#2

Have you already defined all variables being used here?

What keyword must be used to create an instance of a class in Java?

You are calling a method of the Dog class? What is the nature of the method? is it static(how do you call the method) or non static(how then would yo call the method)

Are you spelling out the commands correctly?


#3

Basically what @rydan Is trying to say is:

First Error:

This is that instead of creating the int Dog. Create the int Age. Since you cant out of nowhere without creating an integer just compare it..

So instead of this:

Do this:

int age;

Second Error:

The correct way of printing is System.out.println("Woof!");

Third Error:

That is not a correct way to create an instance, this is how you do it: Dog spike = new Dog(12)

Fourth/Fifth Error:

Your not calling methods on your Dog class...? Your doing it to your new Dog/Instance of dog so like this:

spike.bark()

Hope this helped!


#4

Thanks for the help everyone. It's running now.