Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create two Java subclasses of your Person class called Student and Teacher. For

ID: 3821859 • Letter: C

Question

Create two Java subclasses of your Person class called Student and Teacher. For the Student class, include the following attributes college and dorm. The Teacher class needs the following attribute room # and one or more courses. For the add courses, our assignment requires that we use an ArrayList Group. You must have your constructors and methods for your classes including a method for printing the attributes.  

Also, there shoud be a StudentTest and TeacherTest to test data for the classes.

This is the outline of what our teacher wants:

   Person.java

Student.java

addCourse() ArrayList Group

fname getters/setters lname toString age gender ssn

Explanation / Answer

import java.util.*;
import java.lang.*;
import java.io.*;
class Person
{
String fname,lname,gender;
int age,ssn;
public Person()
{
fname = "null";
lname = "null";
gender = "null";
age = 0;
ssn = 0;
}
public void stud_det()
{
Scanner scan = new Scanner(System.in);
System.out.println(" Enter First Name:");
fname = scan.nextLine();
System.out.println(" Enter Last Name:");
lname = scan.nextLine();
System.out.println(" Enter Age:");
age = scan.nextInt();
System.out.println(" Enter Gender:");
gender = scan.nextLine();
System.out.println(" Enter SSN number:");
ssn = scan.nextInt();
}
public void stud_disp()
{
System.out.println(" Student First Name:" +fname);
System.out.println(" Student Last Name:" +lname);
System.out.println(" Student Age:" +age);
System.out.println(" Student Gender:" +gender);
System.out.println(" Student SSN:" +ssn);
}
}
class Student extends Person
{
   String coll_name, dorm_name;
   public Student()
   {
   coll_name = "null";
   dorm_name = "null";
   }
   public void coll_det()
   {
   Scanner scan = new Scanner(System.in);
   System.out.println(" Enter College Name:");
   coll_name = scan.nextLine();
   System.out.println(" Enter Dorm Name:");
   dorm_name = scan.nextLine();
   }
   public void coll_disp()
   {
   System.out.println(" Student Details");
   System.out.println(" College Name:" +coll_name);
   System.out.println(" Dorm Number" +dorm_name);
   }
}
class Teacher extends Person
{
int room;
String course_name;
public Teacher()
{
room = 0;
course_name = "null";
}
public void room_det()
{
Scanner scan= new Scanner(System.in);
System.out.println(" Enter Room No.");
room = scan.nextInt();
System.out.println(" Enter Course Name:");
course_name = scan.nextLine();
}
public void room_disp()
{
System.out.println(" Student Room No." +room);
System.out.println(" Student Course Name:" +course_name);
}
}
class Detail
{   
public static void main(String args[])
   {
   Person per = new Person();
   per.stud_det();
   per.stud_disp();
   Student stud = new Student();
   stud.coll_det();
   stud.coll_disp();
   Teacher teach = new Teacher();
   teach.room_det();
   }
}