Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Dog Class

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Dog Class

    public class Dog
    {

    private String name = newString(); // instance variables
    private String breed = newString();
    private int heightInInches;

    public void setName(String n) // mutator method for name
    {
    name = n;
    }

    public String getBreed() // accessor method for breed
    {
    return breed;
    }

    public void setBreed(String b) // mutator method for breed
    {
    breed = b;
    }

    public int getHeight()
    {
    return heightInInches;
    }

    public void setHeight(int h) // mutator method for height in inches
    {
    if(h >= 1 && h <= 40)
    {
    heightInInches = h;
    }
    else
    {
    System.out.print("Invalid height");
    }
    }

    public String toString() // toString method
    {
    return "Name: " + name + " Breed: " + breed +
    " Height: " + heightInInches;
    }
    } // end of class

    Errors:
    Dog.java:12: cannot find symbol
    symbol : method newString()
    location: class Dog
    private String name = newString(); // instance variables
    ^
    Dog.java:13: cannot find symbol
    symbol : method newString()
    location: class Dog
    private String breed = newString();
    ^
    2 errors


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    The correct way to declare a variable is String astring = new String(); not String astring = newString();

  3. The Following User Says Thank You to felimblack For This Useful Post:

    mwardjava92 (February 11th, 2012)

Similar Threads

  1. Replies: 7
    Last Post: July 21st, 2011, 02:29 PM
  2. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM
  3. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM
  4. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 10:40 PM
  5. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM