makehaste 0 Newbie Poster

I'm working on a program that demonstrates polymorphism. It asks the user to create an elementary, high school, or college student. Once a student is created, it is stored in an array list. When prompted, the program is suppose to print out each of the student's information.

How do I go about printing this information, and making sure the appropriate printString methods are called?

Main Class:

import java.util.ArrayList;
import java.util.Scanner;

// Student Application

public class StudentApp {



    private static ArrayList<Student> students = new ArrayList<Student>();

   public static void main(String[] args)
   {
       String studName, schoolName, teachName, counselor, major, location;
       double gpa;
       int choice, homeRoom, yearGrad, age;    
       Scanner derp = new Scanner(System.in);

       Student person;

       while (true) {
       System.out.println("Choose one of the following:");     
       System.out.println("1. Create an Elementary School Student. \n2. Create a High School Student." +
            "\n3. Create a College Student. \n4. Print out all students. \n5. Exit");

       choice = derp.nextInt();

       if (choice == 1) {

           System.out.println("Elementary School Student");
           System.out.println("\nName:");
           studName = derp.next();

           System.out.println("Age:");
           age = derp.nextInt();

           System.out.println("School Name:");
           schoolName = derp.next();

           System.out.println("Teacher Name:");
           teachName = derp.next();

           System.out.println("Homeroom:");
           homeRoom = derp.nextInt();  

           System.out.println("Address:");
           location = derp.next();

           person = new elementarySchoolStudent(studName, age, location, schoolName, teachName, homeRoom);
           students.add(person);

       }

       if (choice == 2) {

           System.out.println("High School Student");
           System.out.println("\nName:");
           studName = derp.next();

           System.out.println("Age:");
           age = derp.nextInt();

           System.out.println("School Name:");
           schoolName = derp.next();

           System.out.println("Counselor Name:");
           counselor = derp.next();

           System.out.println("Year of Graduation:");
           yearGrad = derp.nextInt();

           System.out.println("GPA:");
           gpa = derp.nextDouble();

           System.out.println("Address:");
           location = derp.next();

           person = new highSchoolStudent(studName, age, location, schoolName, counselor, yearGrad, gpa);
           students.add(person);

       }

       if (choice == 3) {

           System.out.println("College Student");
           System.out.println("\nName:");
           studName = derp.next();

           System.out.println("Age:");
           age = derp.nextInt();

           System.out.println("School Name:");
           schoolName = derp.next();

           System.out.println("Major:");
           major = derp.next();        

           System.out.println("GPA:");
           gpa = derp.nextDouble();

           System.out.println("Address:");
           location = derp.next();

           person = new CollegeStudent(studName, age, location, schoolName, major, gpa);
           students.add(person);
       }

       if (choice == 4){

           printReport();

       }

       if (choice == 5) {
           System.exit(0);
       }

       }


   }
// print all students in ArrayList by calling the printStudent
   public static void printReport()
   {

       }
      // for all students in the ArrayList
      // print out the student info using printStudent method
   }

Abstract Class:

//abstract student class definition

public abstract class Student{
   private String name;
   private int age;
   private String address;

   public Student(String n, int a, String add)
   { name = n; age = a; address = add; }
   public String getName(){return name;}
   public int getAge(){return age;}
   public String getAddress(){return address;}
   public abstract String printStudent();
}

Other Classes:

// high school class definition

public class highSchoolStudent extends Student{
   private String highSchoolName;
   private String counselorName;
   private int yearOfGraduation;
   private double gpa;

   public highSchoolStudent(String n, int a, String add,
          String highsch, String counselor,
          int year, double g)
   {
      super(n, a, add);
      highSchoolName = highsch;
      counselorName = counselor;
      yearOfGraduation = year;
      gpa = g; }
   public String getCounselor(){return counselorName;}
   public double getGpa(){return gpa;}
   public String getHighSchoolName() {return highSchoolName;}
   public int getGraduationYear() {return yearOfGraduation;}
   //public String toString(){}
   public String printStudent()
 {String report = getName() + "  Age: " + getAge()+
                 "  Attends: " + highSchoolName + "  High School Counselor: " + counselorName +
                 "  Year of Graduation: " + yearOfGraduation +
                 "  GPA: " + gpa;
  return report;}
}

Other Classes:

// College student definition

public class CollegeStudent extends Student{
   private String collegeName;
   private String major;
   private double gpa;

   public CollegeStudent(String n, int a, String add,
          String college, String mjr, double g)
   {
      super(n, a, add);
      collegeName = college;
      major = mjr;
      gpa = g; }

   public String getMajor(){return major;}
   public double getGpa(){return gpa;}
   public String getCollegeName() {return collegeName;}
   //public String toString(){}
   public String printStudent()
   {
     String report = getName() + "  Age: " + getAge()+
         "  Attends: " + collegeName +"  Major: " + major +
         "  GPA: " + gpa;
     return report;
   }
}

Other Classes:

// elementary school class definition

public class elementarySchoolStudent extends Student{
   private String elementarySchoolName;
   private String teachersName;
   private int homeroom;

   public elementarySchoolStudent(String n, int a,
          String add, String elemsch, String teacher,
          int room)
   {
      super(n, a, add);
      elementarySchoolName = elemsch;
      teachersName = teacher;
      homeroom = room;}
   public String getTeachersName(){return teachersName;}
   public String getElemSchoolName() {return elementarySchoolName;}
   public int getHomeRoom() {return
      homeroom;}
   //public String toString(){}
   public String printStudent(){
   String report = getName() + "  Age: " + getAge()+
                 "  Attends: " + elementarySchoolName +
                 "  Homeroom: " + homeroom +
                 "  Teacher: " + teachersName;
   return report;}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.