I was trying to write Java code for this design class Diagram. This question came in past exams.

I couldn't properly understand the relation of FullTimeStudent and PartTimeStudent with PHDprogram. If there is any other mistake in my code do correct me.

enter image description here

Here is my code

class student{ int registration;String name;public void setName ( String name ) {this.name = name;}}class FullTimeStudent extends student{}class PartTimeStudent extends student{}interface course{ void setInstructorName(String name);}class PhdCourse implements course{int courseCode;String coursename;String courseArea;String courseInstructor;@Overridepublic void setInstructorName (String name) { this.courseInstructor = name;}}class PHDTheasis{ int code; String topic; String area; }class PHDprogram{FullTimeStudent ft;PartTimeStudent pt;int deptcode;public void registerCourse(PhdCourse c){}public void registerTheasis(PHDTheasis t){}}
1

Best Answer


Here is image from Wikipedia and other answer from stackoverflow Direction of the association arrow in UML class diagrams

uml

Summarizing this two sources your code should look next way

class PHDprogram {List<FullTimeStudent> ft;PartTimeStudent pt;...}

And optionally you can add relation from FullTimeStudent and PartTimeStudent sides

class PartTimeStudent {PHDprogram phdProgram;}class FullTimeStudent {PHDprogram phdProgram;}