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: Problems with driver class

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Problems with driver class

    Ok hello! I am working on a driver class in java and I have pretty much followed what the book says and I have yet to get this right. Help would be greatly appreciated. Below is the task I am working on plus error messages:


    "Create a driver class called PetStore, whose main method instantiates six puppy objects (make up breeds, colors, and weights) and prints out who is for sale (print all 6 puppy objects). Use the setter methods to modify the breed of 2 puppies, the color of 2 different puppies, and the weight of the remaining 2 puppies. Use the getter method in a statement to print the puppies whose breed, color or weight were changed. "

    I can get my puppy class to compile with no problem:

     
    public class Puppy
    {
      String color,breed;
      double weight;
      double food ;
     
      public Puppy (String newBreed,String newColor,double newWeight,double newFood)
    {
     breed= newBreed;
     weight= newWeight;
     color= newColor;
     food= newFood;
      }
      public String getBreed()
      {
      return breed;
      }
      public String getColor()
      {
      return color;
      }
      public double getWeight()
      {
      return weight;
      }
      public double getFood()
      {
      double DOG_FOOD = 0.84;
      return weight * DOG_FOOD;
      }
      public String toString()
      {
      String description;
      description= " The color of the puppy is " + color + ".\n" +
      "The breed of the puppy is " + breed + " and is " + weight + "pounds.\n"+
      "The recommended amount to feed your puppy is " + getFood() + "ounces." ;
      return description;
      }
    }


    It is my driver class that I am getting wrong:

    public class PetStore
    {
       public static void main (String[] args)
       {
     
          Puppy p1 = new Puppy ("brown","lab", 4.5);
     
          Puppy p2 = new Puppy ("white","poodle",3.5);
     
          System.out.println( "The puppy is a  " + p2.getBreed() + "and is\n\t " + p2.getColor+
          "and currently weighs " + p2.getWeight()+ ".\n\t" + "feed your new puppy " +p2.getFood+
          "ounces twice a day.");
     
     
     
          System.out.println(p1);
          System.out.println(p2);
     
     
       }
     
     }

    and error messages:


     ----jGRASP exec: javac -g PetStore.java
     
    PetStore.java:12: error: constructor Puppy in class Puppy cannot be applied to given types;
          Puppy p1 = new Puppy ("brown","lab", 4.5);
                     ^
      required: String,String,double,double
      found: String,String,double
      reason: actual and formal argument lists differ in length
    PetStore.java:14: error: constructor Puppy in class Puppy cannot be applied to given types;
          Puppy p2 = new Puppy ("white","poodle",3.5);
                     ^
      required: String,String,double,double
      found: String,String,double
      reason: actual and formal argument lists differ in length
    PetStore.java:16: error: cannot find symbol
          System.out.println( "The puppy is a  " + p2.getBreed() + "and is\n\t " + p2.getColor+
                                                                                     ^
      symbol:   variable getColor
      location: variable p2 of type Puppy
    PetStore.java:17: error: cannot find symbol
          "and currently weighs " + p2.getWeight()+ ".\n\t" + "feed your new puppy " +p2.getFood+
                                                                                        ^
      symbol:   variable getFood
      location: variable p2 of type Puppy
    4 errors


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Problems with driver class

    reason: actual and formal argument lists differ in length
    The compiler sees that the arguments lists for the Puppy class don't match
    Look at the Puppy class's constructor and compare it to the new statement that is calling the constructor.
    The arguments must match.

    cannot find symbol variable getColor
    The compiler recognizes method names by their ending (). Without the () the compiler is looking for a variable.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Cannot create JDBC driver of class '' for connect URL 'null'
    By akash_ju in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 29th, 2013, 01:11 PM
  2. Writing a Driver Program to interact with a Class?
    By ViewtifulAaron in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2013, 06:12 AM
  3. Class Driver help
    By Kseidel in forum Object Oriented Programming
    Replies: 2
    Last Post: November 2nd, 2012, 01:06 PM
  4. [SOLVED] Help with creating a class and driver
    By JackCannon15 in forum Object Oriented Programming
    Replies: 1
    Last Post: October 27th, 2011, 03:50 PM
  5. Link From A Driver Class To The Subclasses
    By angels in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 29th, 2011, 07:39 AM

Tags for this Thread