-
having problems
can any one help me with this program i am getting 8 errors????
Design and implement a class called Dog that contains instance data that represents the dog's name and age. Define the Dog constructor to accept and initialize instance data. Include getter and setter methods for the name and age. Include a method to compute and return the age of the dog in "person years" (seven times the dog's age), Include a toString method that returns a one-line description of the dog. Create a driver class called Kennel, whose main method instantiates and updates several Dog objects.
public class dog
{
private String name; // declare instance data
private int age
public Dog(String n, int a)
name = n;
age = a;
}
public void setName(String n) //declare set methods
name = n;
}
public void setAge(int a)
age = a;
}
// declare get methods
public String getName()
return name;
}
public int getAge() {
int humanYears = 0;
humanYears = (age*7);
} return humanYears;
public String toString() //public toString method
String description = "Name: " +name+ ", Age (human years):
"+getAge()+", Age (dog years): " +age;
return description;
}
}
-
You are missing quite a few semicolons and curly braces
-
you mention you have 8 errors but don't tell us what they are?
-
You need to add one to two lines at a time, compile the code immediately after adding those lines and fixing any errors before trying to add any more lines. The key is to never add good code to bad code.
Luck.
-
these are the errors what should I do? or what am I doing worng:
C:\Windows\System32\Dog.java:11: ';' expected
^
C:\Windows\System32\Dog.java:14: <identifier> expected
age = a;
^
C:\Windows\System32\Dog.java:17: 'class' or 'interface' expected
public void setName(String n) //declare set methods
^
C:\Windows\System32\Dog.java:19: 'class' or 'interface' expected
}
^
C:\Windows\System32\Dog.java:38: unclosed string literal
String description = "Name: " +name+ ", Age (human years):
^
C:\Windows\System32\Dog.java:39: unclosed string literal
"+getAge()+", Age (dog years): " +age;
^
C:\Windows\System32\Dog.java:45: 'class' or 'interface' expected
^
7 errors
-
This code is full of errors including missing curly bracket errors. It needs the ole Yeller therapy: Your best bet is to just put it out of its misery and start over.
Do your coding as I stated above. Start with a skeleton of your class (Of course your program will have a different class name):
Code:
public class MyClass
{
public MyClass()
{
}
}
Compile your code first to make sure that there are no compile errors. Then start adding code 1-2 lines at a time, compiling after each addition, and fixing each error that you come across. Again, and I can't stress this enough: Do not add any code until all errors in the current code have been fixed.
Also, please read your notes and / or your text on what you need to have in a class to make it work out. You may not have done this yet.
Good luck.
-
You should try making your program in stages, if you go ahead and write a program without testing it at stages, you will find yourself getting bugs which cannot trace, just like this..
I would suggest creating a new project then importing this source in stages, so you can easily locate the errors and fix them.
Also use the java error messages, "C:\Windows\System32\Dog.java:11: ';' expected". This is telling you that the java compiler expects a semi colon, at the line 11.
So, add a semi colon at the end of line 11, and you now just have 6 errors :)
edit: Furbarable beat me too it :P