Kennel

Directions

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.

Dog class

Create a file named Dog.java and add the following code.

public class Dog
{
    // instance variables

    // constructors

    // accessor methods

    // mutator methods
	
}

Instance Variables

  1. Declare a variable of type String named name.
  2. Declare a variable of type String named breed.

Constructors

  1. Implement a default constructor.
  2. Implement a second constructor which allows a client to assign initial values to name and breed.

Accessor Methods

  1. Implement an accessor method for each instance variable.

Mutator Methods

  1. Implement a mutator method for each instance variable.

Kennel class

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();
    }
}

addDogs Method

  1. Implement the method addDogs. This method allows a user to enter information for 5 dogs and store this information in the array dogs.

    Here is the pseudocode for the method.
    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

printDogs Method

  1. Implement the method printDogs. This method displays the name and breed for each dog in the array.

    Here is the pseudocode for the method.
    loop I from 0 to 4
       output DOGS[I].getName();
       output DOGS[I].getBreed();
    end loop

Source File

Dog.java

Kennel.java

Sample Run

************************
*       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