Results 1 to 7 of 7

Thread: having problems

  1. #1
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Unhappy 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;
    }
    }

  2. #2
    sari's Avatar
    sari is offline Member
    Join Date
    Jan 2009
    Posts
    32
    Rep Power
    0

    Default

    You are missing quite a few semicolons and curly braces
    If you don't try you can't succeed.

  3. #3
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you mention you have 8 errors but don't tell us what they are?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  5. #5
    Join Date
    Feb 2009
    Posts
    12
    Rep Power
    0

    Default

    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

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

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

    Java 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.

  7. #7
    sirwiggles's Avatar
    sirwiggles is offline Member
    Join Date
    Feb 2009
    Posts
    31
    Rep Power
    0

    Default

    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
    Last edited by sirwiggles; 02-06-2009 at 11:37 PM.

Similar Threads

  1. GUI problems.
    By saytri in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 10:27 PM
  2. many to many problems
    By cecily in forum JDBC
    Replies: 1
    Last Post: 08-02-2007, 05:51 PM
  3. gui problems
    By bluebirdjc in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2007, 05:38 PM
  4. a few problems
    By gary in forum AWT / Swing
    Replies: 0
    Last Post: 07-11-2007, 04:57 PM
  5. problems with JPA
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 05:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •