📄 departmentset.java
字号:
package Sets;
import Entities.*;
import dslib.dictionary.arrayed.ArrayedPKeyedDictUos;
import java.io.*;
/** This class provides access to a dictionary that contains
the departments that are currently part of the university.
It should be noted that departments contain courses and courses
have sections, so access to courses and course
sections should be made by accessing this class' dictionary. */
public class DepartmentSet
{
/** Provides access to the dictionary of departments. */
public static ArrayedPKeyedDictUos rep;
public static void displayNames()
{
System.out.println("Departments:");
System.out.println("Computer Science, code: 865, type: 1");
System.out.println("Physics, code: 345, type: 2\n");
System.out.println("Courses:");
System.out.println("Computer Science Courses:");
System.out.println("Number: 360, Credits: 3, \"A study of machines and algorithms.\"");
System.out.println("Section: Section number: 2, MWF 9:30-10:30, size: 30");
System.out.println("Number: 317, Credits: 3, \"An Introduction to Artificial Intelligence.\"");
System.out.println("Section: Section number: 1, TTH 11:30-13:00, size: 120");
System.out.println("Physics Courses:");
System.out.println("Number: 327, Credits: 3, \"An introduction to waves and optics.\"");
System.out.println("Section: Section number: 2, MWF 11:30-12:30, size: 20\n");
}
static //execute only once (never explicitly called though)
{
rep = new ArrayedPKeyedDictUos(10);
/** Make Computer Science one of the departments */
Department d = new Department("Computer Science", 865, 1);
/** Add a Computer Science course with one section */
rep.insert(new Integer(865) ,d);
rep.search(new Integer(865));
Course c = new Course(360, 3, "A study of machines and algorithms.");
SectionDetails sd = new SectionDetails(2,"9:30 - 10:30","MWF",30);
CourseSection s = new CourseSection(1, sd);
c.addSection(s);
((Department)rep.item()).addCourse(c);
/** Add another Computer Science course with one section */
c = new Course(317,3,"An introduction to artificial intelligence.");
sd = new SectionDetails(1,"11:30 - 13:00", "TTH",120);
s = new CourseSection(1, sd);
c.addSection(s);
((Department)rep.item()).addCourse(c);
/** Make a Physics department */
d = new Department("Physics", 345, 2);
rep.insert(new Integer(345) ,d);
/** Add a Physics course with one section */
rep.search(new Integer(345));
c = new Course(327,3,"An introduction to waves and optics.");
sd = new SectionDetails(2,"11:30 - 12:30","MWF",20);
s = new CourseSection(1, sd);
c.addSection(s);
((Department)rep.item()).addCourse(c);
}
/** Return the department with number 'deptNum'
Analysis : Time = O(1) */
public static Department getDepartment(int deptNum)
{
return (Department)rep.obtain(new Integer(deptNum));
}
/** Return the course with department number deptNum and
course number courseNum
Analysis : Time = O(1) */
public static Course getCourse(int deptNum, int courseNum)
{
Department dept = getDepartment(deptNum);
if (dept != null)
return (Course)dept.courses.obtain(new Integer(courseNum));
else
return null;
}
/** Return the course section that is designated by the arguments
Analysis : Time = O(1) */
public static CourseSection getCourseSection(CallNum nums)
{
Course cou = getCourse(nums.deptNum(), nums.courseNum());
if (cou != null)
return cou.sections[nums.sectionNum()];
else
return null;
}
/** Add an instructor to a department
Analysis : Time = O(1) */
public static void addInstructor(Instructor i, int subjectCode)
{
((Department)rep.obtain(new Integer(subjectCode))).addInstructor(i);
}
} /* end of DepartmentSet */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -