Question: / * APCSA Ch 8 2 CBU 0 9 6 _ 4 _ Pet Adapted from College Board Unit 9 . 6 , FRQ# 1
APCSA ChCBUPet
Adapted from College Board Unit FRQ# 'Pet'
Burkham,
PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.
Assume that the classes listed in the Java Quick Reference have been
imported where appropriate.
Unless otherwise noted in the question, assume that parameters in method calls
are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods
that are listed in classes defined in that question. Writing significant amounts of
code that can be replaced by a call to one of these methods will not receive full credit.
The Pet class is used to represent pets and print information about each pet.
Each Pet object has attributes for the pet name and species.
The Dog class is a subclass of the Pet class that has one additional attribute:
a String variable named breed that is used to represent the breed of the dog.
The Dog class also contains a printPetInfo method to print the name and breed of the dog.
CONDITIONS:
Up to Java statements total for all parts may be added
Other lines of code may not be changed
Your final implementation should conform to the 'FINAL OUTPUT' example at end
Format, line spacing, etc. must match exactly
NOTES:
Properly use at least one method super.
Do not use any getter method!!
Use a comment for each line.
PART A:
Consider the following code segment.
Pet pet new PetFloppy "rabbit";
Pet pet new PetArty "dog";
petprintPetInfo;
petprintPetInfo;
The code segment is intended to print the following output.
Floppy is a rabbit
Arty is a dog
Complete the Pet method printPetInfo
PART B:
Consider the following code segment.
Dog fluffy new DogFluffy "pomeranian";
fluffy.printPetInfo;
The code segment is intended to print the following output.
Fluffy is a dog of breed pomeranian
Complete the Dog method printPetInfo
PART C:
The PetOwner class below is used to generate a description about a pet and its owner.
The PetOwner constructor takes a Pet object and a String value representing the name
of the pet owner as parameters.
Code Segment Result Printed
ownerprintOwnerInfo; Floppy is a rabbit owned by Jerry
ownerprintOwnerInfo; Arty is a dog of breed pug owned by Kris
Complete the PetOwner method printOwnerInfo
FINAL OUTPUT:
The final formatted output all parts completed should be exactly this:
Floppy is a rabbit
Arty is a dog
Fluffy is a dog of breed pomeranian
Floppy is a rabbit owned by Jerry
Arty is a dog owned by Kris
public class ChCBUaPetSTU
public static void main String args
Pet pet new PetFloppy "rabbit";
Pet pet new PetArty "dog";
petprintPetInfo;
petprintPetInfo;
Dog fluffy new DogFluffy "pomeranian";
fluffy.printPetInfo;
PetOwner owner new PetOwnerpet "Jerry";
PetOwner owner new PetOwnerpet "Kris";
ownerprintOwnerInfo;
ownerprintOwnerInfo;
class Pet
private String name;
private String species;
public PetString n String s
name n;
species s;
public String getName
return name;
public void printPetInfo
to be implemented in PART A
class Dog extends Pet
private String breed;
public DogString n String b
supern "dog";
breed b;
public void printPetInfo
to be implemented in PART B
class PetOwner
private Pet thePet;
private String thePetOwner;
public PetOwnerPet p String o
super;
thePet p;
thePetOwner o;
public void printOwnerInfo
to be implemented in PART C
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
