Question: Teach me how to //replace with keyboard input yourself in the main And Output all the information stored (including the baby sound) in the Baby

Teach me how to

//replace with keyboard input yourself in the main

And

Output all the information stored (including the baby sound) in the Baby array to a file (Baby.txt)

Explain what is polymorphism, and explain any polymorphism that you think is occurring in the above exercises.

Thank you.

public class Client {    public static void main(String[] args) {  Baby[] babies = new Baby[4];    // replace with keyboard input yourself  System.out.println("Enter Baby name, age and identification number.")    Patient baby1 = new Patient("Baby1", 1, 111);  babies[0] = baby1;    Baby baby2 = new Baby("Baby2", 2);  babies[1] = baby2;    Playgroup baby3 = new Playgroup("Baby3", 1);  babies[2] = baby3;    Baby baby4 = new Baby("Baby4", 2);  babies[3] = baby4;    // output all patient baby information  System.out.println("Patient:");  for (int i = 0; i < babies.length; i++) {  Baby baby = babies[i];  if (baby instanceof Patient) {  baby.display();  baby.babySound();  System.out.println();  }  }    // output all Patient baby information  System.out.println("Playgroup:");  for (int i = 0; i < babies.length; i++) {  Baby baby = babies[i];  if (baby instanceof Playgroup) {  baby.display();  baby.babySound();  System.out.println();  }  }    // output all all baby information  // Output all the information stored (including the baby sound) in the Baby  // array to a file (Baby.txt)  System.out.println("All babies information");  for (int i = 0; i < babies.length; i++) {  Baby baby = babies[i];  baby.display();// print it to a file  baby.babySound();// print it to a file  System.out.println();  }  }    }


Step by Step Solution

3.39 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To replace keyboard input in the main method you can use the Scanner class in Java Heres an example ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!