Requirements: This is what I need to add to the program: --Create a new class called Dog, derived from petRecord class. With additional attributes (breed)type string and (boosterShot)type boolean, true if the pet has had it's boostershot, false if not. ---write a driver program to test all methods, and write program that reads in five pets of type Dog and print the name and breed of all dogs that are over two years old and have had their booster shots. //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// ///////
public class PetRecord { private String name; private int age;//in years private double weight;//in pounds
public PetRecord(String initialName, int initialAge, double initialWeight) { name = initialName; if ((initialAge < 0) || (initialWeight < 0)) { System.out.println("Error: Negative age or weight."); System.exit(0); } else { age = initialAge; weight = initialWeight; } }
public void set(String newName, int newAge, double newWeight) { name = newName; if ((newAge < 0) || (newWeight < 0)) { System.out.println("Error: Negative age or weight."); System.exit(0); } else { age = newAge; weight = newWeight; } }
public PetRecord(String initialName) { name = initialName; age = 0; weight = 0; }
public void set(String newName) { name = newName; //age and weight are unchanged. }
public PetRecord(int initialAge) { name = "No name yet."; weight = 0; if (initialAge < 0) { System.out.println("Error: Negative age."); System.exit(0); } else age = initialAge; }
public void set(int newAge) { if (newAge < 0) { System.out.println("Error: Negative age."); System.exit(0); } else age = newAge; //name and weight are unchanged. }
public PetRecord(double initialWeight) { name = "No name yet"; age = 0; if (initialWeight < 0) { System.out.println("Error: Negative weight."); System.exit(0); } else weight = initialWeight; }
public void set(double newWeight) { if (newWeight < 0) { System.out.println("Error: Negative weight."); System.exit(0); } else weight = newWeight; //name and age are unchanged. }
public PetRecord() { name = "No name yet."; age = 0; weight = 0; }
public String getName() { return name; }
public int getAge() { return age; }
public double getWeight();
return Weight;
{ PetRecord usersPet = new PetRecord("Stitch"); System.out.println("My records on your pet are inaccurate."); System.out.println("Here is what they currently say:"); usersPet.writeOutput();
System.out.println("Please enter correct pet name:"); String correctName = SavitchIn.readLine(); System.out.println("Please enter corect pet age:"); int correctAge = SavitchIn.readLineInt(); System.out.println("Please enter correct pet weight:"); double correctWeight = SavitchIn.readLineDouble(); usersPet.set(correctName, correctAge, correctWeight); System.out.println("My updated records now say:"); usersPet.writeOutput();
System.out.println("Correct pet name is Stitch:"); System.out.println("Correct pet age is 8:");
System.out.println("Correct pet weight is 40lbs:");
System.out.println("My updated records now say:");
} }
public class Dog extends PetRecord {
private int dogBreed;
public Dog() { super(); dogBreed = terrier; }
public Dog(String breed, int boosterShot) { super(Initialbreed); booster = initialboosterShot; }
public void reset(String newName, int newbreed) {
setName(newName); boosterShot = newboosterShot; }
public int getBreed() {
return breed; }
public void setboosterShot(int newboosterShot) { boosterShot = newboosterShot; }
> Requirements: > This is what I need to add to the program: > --Create a new class called Dog, derived from petRecord > class. With additional attributes (breed)type string and > (boosterShot)type boolean, true if the pet has had it's > boostershot, false if not. > ---write a driver program to test all methods, and write > program that reads in five pets of type Dog and print the > name and breed of all dogs that are over two years old and > have had their booster shots.
Okay, so do it. And let us know what specific questions you have.
You can use the Artima SuiteRunner or JUnit for the "driver program to test all methods" instead of writing your own, by the way.
> <snipp>several gazillion gigabytes of left-justified code</snip>
Please use the [ java ] and [ /java ] tags, especially when posting a ton of code. See the gray Formatting Your Post box to the right when you are posting for instructions.