Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Kennel {
- // instance variable
- private static Dogs[] dogs; // declare array variable
- // constructor
- public Kennel(){
- dogs = new Dogs[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);
- for (int i = 0; i < 5; i++) {
- System.out.println("Enter the name of the dog.");
- String name = keyboard.next();
- System.out.println("Enter the breed of the dog.");
- String breed = keyboard.next();
- dogs[i] = new Dogs (name, breed);
- }
- }
- /* This method displays the name and breed for each Dog in the array.
- */
- public void printDogs(){
- for(int i = 0; i < 5; i++) {
- System.out.print(dogs[i].getName() + " ");
- System.out.print(dogs[i].getBreed() + ". ");
- }
- System.out.println();
- }
- public static void main(String[] args){
- Kennel app = new Kennel();
- app.addDogs();
- app.printDogs();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement