In: Computer Science
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart or another diagramming tool. If you can’t find a diagramming tool, you can hand draw the diagram but make sure it is legible.
Points to remember:
• Include all classes on your diagram. There are nine of them.
• Include all the properties and methods on your diagram.
• Include the access modifiers on the diagram. + for public, - for private, ~ for internal, # for protected
• Include the proper association lines connecting the classes that “know about” each other.
o Associations
o Dependencies
o Inheritance
o Aggregation
o Composition
• Static classes are designated on the diagram with > above the class name, and abstract classes are designated with > above the class name.
-------------------------------------------------------------------
static class GlobalValues
{
private static int maxStudentId = 100;
public static int NextStudentId
{
get
{
maxStudentId += 1;
return maxStudentId;
}
}
}
class College
{
public string Name { get; set; }
public Dictionary<string, Department> Departments { get; } =
new Dictionary<string, Department> { };
internal College()
{
Departments.Add("ART", new ArtDept() { Name = "Art Dept" });
Departments.Add("MATH", new MathScienceDept() { Name = "Math
/Science Dept" });
}
}
abstract class Department
{
public string Name { get; set; }
public Dictionary<string, Course> CourseList { get; } = new
Dictionary<string, Course> { };
protected abstract void FillCourseList();
// Department constructor
public Department()
{
// When a department is instantiated fill its course list.
FillCourseList();
}
}
class ArtDept : Department
{
protected override void FillCourseList()
{
CourseList.Add("ARTS101", new Course(this, "ARTS101") { Name =
"Introduction to Art" });
CourseList.Add("ARTS214", new Course(this, "ARTS214") { Name =
"Painting 2" });
CourseList.Add("ARTS344", new Course(this, "ARTS344") { Name =
"American Art History" });
}
}
class MathScienceDept : Department
{
protected override void FillCourseList()
{
CourseList.Add("MATH111", new Course(this, "MATH111") { Name =
"College Algebra" });
CourseList.Add("MATH260", new Course(this, "MATH260") { Name =
"Differential Equations" });
CourseList.Add("MATH495", new Course(this, "MATH495") { Name =
"Senior Thesis" });
}
}
class Course
{
public readonly Department Department;
public readonly string Number;
private List<Enrollment> Enrollments { get; } = new
List<Enrollment> { };
public string Name { get; set; }
internal Course(Department department, string number)
{
Department = department;
Number = number;
}
public void Enroll(Student student)
{
Enrollments.Add(new Enrollment(this, student));
Console.WriteLine($"{ student.Name } has been enrolled in \"{ Name
}\".");
}
}
class Student
{
public readonly int Id;
private string name;
public string Name
{
get { return name; }
set
{
name = value;
Console.WriteLine($"{ name } is student ID: { Id }.");
}
}
// New Student constructor with a Student.Id
internal Student(int id)
{
Id = id;
}
// New Student constructor without a Student.Id
internal Student()
{
Id = GlobalValues.NextStudentId;
Console.WriteLine($"A new student has been assigned ID: \"{ Id
}\".");
}
}
class Enrollment
{
public readonly Student Student;
public readonly Course Course;
internal Enrollment(Course course, Student student)
{
Student = student;
Course = course;
}
}
class Program
{
static void Main()
{
College MyCollege = new College();
Student Justin = new Student() { Name = "Justin" };
Student Gloria = new Student() { Name = "Gloria" };
MyCollege.Departments["ART"].CourseList["ARTS344"].Enroll(Justin);
MyCollege.Departments["ART"].CourseList["ARTS214"].Enroll(Gloria);
MyCollege.Departments["MATH"].CourseList["MATH111"].Enroll(Justin);
MyCollege.Departments["MATH"].CourseList["MATH260"].Enroll(Gloria);
Console.WriteLine("Press Enter to quit...");
Console.ReadLine();
}
}
This UML Class Diagram has been designed in StarUML:
Here, there are 8 total classes since the class containing the "Main()" method is not shown because it only initializes the program and should not be included in the UML diagram. Think of it like an application server and an application server is not something you include in your class diagram.
First, the ArtDept and MathScienceDept classes have been represented to have a Generalization/Inheritance Relation with the Department class. They inherit the properties of the department class since they are sub-classes.
A college and a department have a one-to-many relationship, since one college can have multiple departments.
The student and the enrollment class share a composition relation since the student does not exist when the enrollment is taken away.
The Course class and the Student class share a many-to-many relationship since many students can opt for one or more courses.
Finally, the Course class is dependent on the Enrollments class since the course needs students to enroll into it in order to start with it.