Teach me how to //replace with keyboard input yourself in the main And Output all the information
Fantastic news! We've Found the answer you've been seeking!
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 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(); } } }
Related Book For
Auditing and Assurance services an integrated approach
ISBN: 978-0132575959
14th Edition
Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley
Posted Date: