Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 5 Java statements (total for all 3 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 BONUS: +10 Properly use at least one method super. -AND- Do not use any getter method!! PART A: Consider the following code segment. Pet pet1 = new Pet("Floppy", "rabbit"); Pet pet2 = new Pet("Arty", "dog"); pet1.printPetInfo(); pet2.printPetInfo(); 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 Dog("Fluffy", "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 owner1.printOwnerInfo(); Floppy is a rabbit owned by Jerry owner2.printOwnerInfo(); Arty is a dog of breed pug owned by Kris Complete the PetOwner method printOwnerInfo(). FINAL OUTPUT: The final formatted output (all 3 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

The code: what needs to be inserted in sections a b and c are below

public class Ch82CBU096_1a_Pet_STU { public static void main ( String[] args ) { Pet pet1 = new Pet("Floppy", "rabbit"); Pet pet2 = new Pet("Arty", "dog"); pet1.printPetInfo(); pet2.printPetInfo(); Dog fluffy = new Dog("Fluffy", "pomeranian"); fluffy.printPetInfo(); PetOwner owner1 = new PetOwner(pet1, "Jerry"); PetOwner owner2 = new PetOwner(pet2, "Kris"); owner1.printOwnerInfo(); owner2.printOwnerInfo(); } } class Pet { private String name; private String species;

public Pet(String 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 Dog(String n, String b) { super(n, "dog"); breed = b; } public void printPetInfo() { /* to be implemented in PART B */ } } class PetOwner { private Pet thePet; private String thePetOwner; public PetOwner(Pet 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions