Answer:
All the classes are mentioned with code and screenshots. . That class is shown at last.
Explanation:
Solution
Class.Java:
Code
**
* atauthor your_name
* This class denotes Class at the college.
*
*/
public class Class {
private String className,classID;
private Professor professor;
/**
* atparam className
* atparam classID
* atparam professor
*/
public Class(String className, String classID, Professor professor) {
this.classID=classID;
this.className=className;
this.professor=professor;
}
/**
* at return classID of the class
*/
public String getClassID() {
return classID;
}
/**
* Override toString() from Object Class
*/
public String toString() {
return classID+" "+className+" "+professor.getName()+" "+professor.getEducation();
}
}
Person.Java:
Code:
/**
* atauthor your_name
* This class represents Person
*
*/
public class Person {
protected String name;
/**method to fetch name
* at return
*/
public String getName() {
return name;
}
/**method to set name
* at param name
*/
public void setName(String name) {
this.name = name;
}
Professor.java:
Code:
import java.util.ArrayList;
import java.util.List;
/**
* at author your_name
*
*This class represents professors
*
*/
public class Professor extends Person{
private String professorID, education;
private List<Class> classes=new ArrayList<Class>();
/**
* at param name
* at param professorID
* at param education
*/
public Professor(String name,String professorID,String education) {
this.name=name;
this.professorID=professorID;
this.education=education;
}
/**
* at return
*/
public String getEducation() {
return this.education;
}
/**
* at return
*/
public String getprofessorID() {
return this.professorID;
}
/** to add classes
* at param Class
*/
public void addClass(Class c) {
classes.add(c);
}
/**
* Override toString() from Object Class
*/
public String toString() {
String result=this.getName()+" - "+professorID+" - "+education;
for(Class c:classes) {
result+=c.toString()+"\n";
}
return result;
}
}
}
Student.java:
Code:
import java.util.ArrayList;
import java.util.List;
/**
* This class represents students
* at author your_Name
*
*/
public class Student extends Person{
private String studentID;
private List<Class> classes=new ArrayList<Class>();
/**
* atparam name
* atparam studentID
*/
public Student(String name,String studentID) {
this.name=name;
this.studentID=studentID;
}
/**
* atreturn
*/
public String getStudentID() {
return studentID;
}
/**
* atparam c
*/
public void addClass(Class c) {
classes.add(c);
}
/**
* atreturn
*/
public int getClassCount() {
return classes.size();
}
/**
* Override toString() from Object Class
*/
public String toString() {
String result=this.getName()+" - "+studentID+"\n";
for(Class c:classes) {
result+=c.toString()+"\n";
}
return result;
}
}
NOTE: Kindly find an attached copy of screenshot of the output, which is a part of the solution to this question