Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
To replace keyboard input in the main method you can use the Scanner class in Java Heres an example ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started