How to print a specific object type from an abstract class arraylist in java
<p>the class below is my main class. My arraylist is the type of "Employee" and that arraylist contains many elements which are of multiple objects (polymorphism). So I want to know that when the user enters a class name, I should print out the employees of that specific class from the arraylist. For example, when the user types in "Surgeon", the program should be able to print out all the Surgeon employee's from the arraylist. Please help, thanks in advance. </p>

<pre><code> import java.util.*;


public class HospitalDatabase {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String q;
        String w;
        ArrayList&lt;Employee&gt; e = new ArrayList&lt;Employee&gt;(); 
        Employee s = new Surgeon("Christian Barnard", 2113211, "Cardiac", "Cardiology",
                2000, "Yale University");
        Employee i = new ITSupport("Mickey Mouse", 11280, Department.IT, 26, "Mac OS");
        Employee n = new Nurse("Florence Nightingale", 54678, "Urgent Care", 
                "Emergency", false, HospitalWing.North);
        Employee p = new PatientAccountsManager("Donald Duck", 32465, Department.PatientSupport, 
                99, true); 
        Employee s1 = new Surgeon("Sanjay Gupta", 42171, "Neurosurgery", 
                "Neurology", 500, "Duke University"); 
        Employee n1 = new Nurse("Mary Breckinridge", 56536, "Gynecology", "Midwife",
                true, HospitalWing.West);


        e.add(s);
        e.add(i);
        e.add(n);
        e.add(p);
        e.add(s1);
        e.add(n1);

        System.out.println(e.toString()); 
        System.out.println(Employee.numEmployees);
        System.out.println("-------------******--------------");

        Scanner scan = new Scanner(System.in);
        System.out.println("Enter a name: ");
        q = scan.nextLine();
        boolean j = false; 
        System.out.println("***************");

        for(Employee v: e){
            if(v.name.contains(q)){
                System.out.println(v.name);
                j = true; 
            }
        } 
        if(j == false){
            System.out.println("Name not found");
        }  
        System.out.println("----------------**************---------------");

        Scanner f = new Scanner(System.in);
        System.out.println("Enter the class of employees: ");
        w = f.nextLine();
        System.out.println("***************************"); 

        //PLEASE SHOW THE CODE HERE
    } 
}
</code></pre>