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 5 of 5

Thread: Dog Tester Class

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

    Default Dog Tester Class

    // Tester for Dog class
    // Marcus Ward
    // 11/02/2012

    public class DogTester
    {
    public static void main(String[] args)
    {
    Dog firstDog = new Dog();

    firstDog.setName("Rover");
    firstDog.setBreed("Alsatian");
    firstDog.setHeight("23");

    System.out.print(firstDog.toString());

    }
    }

    Error:
    DogTester.java:13: setHeight(int) in Dog cannot be applied to (java.lang.String)
    firstDog.setHeight("23");
    ^
    1 error


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Dog Tester Class

    The setHeight() method of the Dog class takes in an integer parameter, you're passing it a String.
    Remove the surrounding quotes from 23 and it should work.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

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

    mwardjava92 (February 11th, 2012)

  4. #3
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Dog Tester Class

    Quote Originally Posted by mwardjava92 View Post
    // Tester for Dog class
    // Marcus Ward
    // 11/02/2012

    public class DogTester
    {
    public static void main(String[] args)
    {
    Dog firstDog = new Dog();

    firstDog.setName("Rover");
    firstDog.setBreed("Alsatian");
    firstDog.setHeight("23");

    System.out.print(firstDog.toString());

    }
    }

    Error:
    DogTester.java:13: setHeight(int) in Dog cannot be applied to (java.lang.String)
    firstDog.setHeight("23");
    ^
    1 error
    Besides the wrong argument type passed to the setHeight method, what did you expect to be printed out to the screen after calling the System.out.println() method on that dog object? Printing firstDog.toString will not give you the name, breed, and height as it seems you expect in the above code. good luck.

  5. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Dog Tester Class

    Quote Originally Posted by elisha.java View Post
    Besides the wrong argument type passed to the setHeight method, what did you expect to be printed out to the screen after calling the System.out.println() method on that dog object? Printing firstDog.toString will not give you the name, breed, and height as it seems you expect in the above code. good luck.
    How can you be so sure? Maybe he has actually overridden toString to print his own message.
    Last edited by newbie; February 11th, 2012 at 04:24 PM. Reason: add E onto messagE
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  6. #5
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Dog Tester Class

    I should have mentioned that possibility. Yeah, if he has overridden that method, well and good.

Similar Threads

  1. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM
  2. 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, 09:40 PM
  3. Help with GUI Password Tester
    By java.kid21 in forum AWT / Java Swing
    Replies: 10
    Last Post: December 13th, 2010, 07:06 AM
  4. Password Tester GUI HELP
    By java.kid21 in forum Object Oriented Programming
    Replies: 3
    Last Post: December 7th, 2010, 10:35 PM
  5. bandwith tester
    By messithe1 in forum Java SE APIs
    Replies: 0
    Last Post: January 19th, 2010, 09:37 PM