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