Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the following class diagram and the test program PetClinic.java: Based on the given class diagram and the test program Pet- Clinic.java, implement the classes

image text in transcribed
Given the following class diagram and the test program PetClinic.java: Based on the given class diagram and the test program Pet- Clinic.java, implement the classes Owner, Pet, Cat and Dog in Owner Pet Pet is an abstract class Java. -id : String -id : String getRecord() isan abstract -name : String 1 own -name : String method +Owner(id : String, name : String) Pet(id : String, name : String) Note: Apart from the attributes and methods to classes Owner, Pet +getID() : String 1.. +getRecord() : String +getName() : String +getID() : String getRecord() returns and Cat, it may be necessary to add attributes and methods to clas- +getName() : String the value of attribute dogRecord ses Owner, Pet, Cat and Dog for implementing the one-to-many 4 association and the basic getters/setters. getRecord() L Cat Dog returns ~catRecord : String dog Record : String the value of attribute +Cat(id : String, name : String, catRecord : String) +Dog(id : String, name : String, dogRecord : String) catRecord getRecord() : String +getRecord() : String PetClinic.java: import java. util.*; public class PetClinic { public static void main (String args) { Owner cList = new Owner [2] ; cList [0] = new Owner ("Owner01", "Mary") ; cList [1] = new Owner ("Owner02", "John") ; Pet pets = new Pet [3] ; pets [0] = new Cat ("PET01", "Lucky", "CAT: First visit") ; / /CAT pets [1] = new Cat ("PET02", "Dicky", "CAT: First visit") ; // CAT pets [2] = new Dog ("PET03", "Luci", "DOG: First visit") ; / / DOG cList [0] . addPet (pets [0] ) ; pets [0] . setOwner (cList [0] ) ; cList [0] . addPet (pets [1] ) ; pets [1] . setOwner (cList [0] ) ; cList [1] . addPet (pets [2] ) ; Owner theOwner = cList [0] ; pets [2] . setOwner (cList [1] ) ; 6 getPets method in class Owner is to find and return all Pets of the Owner System. out. printIn ("The list of Owner "+theOwner. getName () +" ( "+theOwner. getID()+" ) own pets:-") ; while (petList . hasMoreElements () ) { Pet thePet = (Pet) (petList. nextElement () ) ; System. out . printIn (thePet. getID() + ", Name: " + thePet. getName () + ", Record: " + thePet. getRecord () )

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions