In this assignment you are going to implement two classes: Dog and Kennel. The Dog class stores information about a dog including the dog's name and breed. The Kennel class is a client of the Dog class. It can store up to 5 Dog objects in an array.
Create a file named Dog.java and add the following code.
public class Dog { // instance variables // constructors // accessor methods // mutator methods }
Create a file named Kennel.java and add the following code.
import java.util.*; public class Kennel { // instance variable private Dog[] dogs; // declare array variable // constructor public Kennel() { dogs = new Dog[5]; // instantiate array with length 5 } /* This method allows a user input information about 5 dogs and * stores this information in the array dogs. */ public void addDogs() { Scanner keyboard = new Scanner(System.in); } /* This method displays the name and breed for each Dog in the array. */ public void printDogs() { } public static void main(String[] args) { Kennel app = new Kennel(); app.addDogs(); app.printDogs(); } }
loop I from 0 to 4 output "Enter dog name -->" input NAME output "Enter dog breed -->" input BREED DOGS[I] = new Dog(NAME, BREED); end loop
loop I from 0 to 4 output DOGS[I].getName(); output DOGS[I].getBreed(); end loop
Dog.java
Kennel.java
************************ * addDogs * ************************ Enter dog name -->Maddie Enter dog breed -->Golden Retriever Enter dog name -->Sam Enter dog breed -->Black Lab Enter dog name -->Mitzy Enter dog breed -->Beagle Enter dog name -->Rex Enter dog breed -->German Sheperd Enter dog name -->Sally Enter dog breed -->mix ************************ * printDogs * ************************ Dog name = Maddie Dog breed = Golden Retriever Dog name = Sam Dog breed = Black Lab Dog name = Mitzy Dog breed = Beagle Dog name = Rex Dog breed = German Sheperd Dog name = Sally Dog breed = mix