MilaDimitrovaa

Start

Nov 16th, 2021
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package com.company.newExercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Start { //Start of class
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scan = new Scanner(System.in);
  10.  
  11.         System.out.println("Write first dog's name: ");
  12.         String firstDogName = scan.nextLine();// Read the first name of the dog
  13.  
  14.  
  15.         Dog firstDog = new Dog(firstDogName); //Create the first dog with parameters
  16.  
  17.  
  18.         System.out.println("Write second dog's name: ");
  19.         String secondDogName = scan.nextLine(); // Read the second name of the dog
  20.  
  21.  
  22.         Dog secondDog = new Dog(); //Create the second dog with default - constructor with default name Sharo
  23.  
  24.         secondDog.setName(secondDogName); //Change name of the second dog
  25.  
  26.  
  27.         Dog thirdDog = new Dog(); //Create the third dog with default - constructor with default name Sharo
  28.  
  29.         Dog[] dogsArray = new Dog[]{firstDog, secondDog, thirdDog};
  30.  
  31.         for (Dog tempDog : dogsArray) {
  32.             tempDog.bark();
  33.         }
  34.     }
  35.  
  36. }//End of class
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment