Advertisement
glee20

Kennel

Oct 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Kennel {
  4.     // instance variable
  5.     private static Dogs[] dogs;     // declare array variable
  6.  
  7.     // constructor
  8.     public Kennel(){
  9.         dogs = new Dogs[5];  // instantiate array with length 5
  10.     }
  11.  
  12.     /* This method allows a user input information about 5 dogs and
  13.      * stores this information in the array dogs.
  14.      */
  15.     public void addDogs() {
  16.         Scanner keyboard = new Scanner(System.in);
  17.         for (int i = 0; i < 5; i++) {
  18.             System.out.println("Enter the name of the dog.");
  19.             String name = keyboard.next();
  20.             System.out.println("Enter the breed of the dog.");
  21.             String breed = keyboard.next();
  22.             dogs[i] = new Dogs (name, breed);
  23.         }
  24.     }
  25.  
  26.     /* This method displays the name and breed for each Dog in the array.
  27.      */
  28.     public void printDogs(){
  29.         for(int i = 0; i < 5; i++)  {
  30.           System.out.print(dogs[i].getName() + " ");
  31.           System.out.print(dogs[i].getBreed() + ". ");
  32.        }
  33.        System.out.println();
  34.     }
  35.  
  36.     public static void main(String[] args){
  37.         Kennel app = new Kennel();
  38.         app.addDogs();
  39.         app.printDogs();
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement