📄 course.java
字号:
package Entities;
import dslib.list.LinkedListUos;
/** This class models a course, that is a description
a possible class you could take at the university */
public class Course
{
protected String description;
protected int number;
public CourseSection sections[];
protected int creditUnits;
public int creditUnits()
{
return creditUnits;
}
public int number()
{
return number;
}
public String description()
{
return description;
}
/** Create a new course from a course number and the
credit units associated with that course */
public Course(int num, int cUnits, String desp)
{
number = num;
creditUnits = cUnits;
description = desp;
sections = new CourseSection[10];
}
/** Set the description of the course to be 'newDescription' */
public void changeDescription(String newDescription)
{
description = newDescription;
}
/** Add a new section for this course */
public void addSection(CourseSection newSection)
{
sections[newSection.secNumber()] = newSection;
}
/** Return the course section 'num' if it exists */
public CourseSection getCourseSection(int num)
{
return sections[num];
}
/** Return a string representation of the sections
associated with this course that have room for more students */
public LinkedListUos openSections()
{
LinkedListUos result = new LinkedListUos();
for (int i = 0; i < sections.length; i++)
if ((sections[i] != null) && (!sections[i].isFull()))
result.insert(sections[i]);
return result;
}
public String toString()
{
String result = "";
result += "\nCurrent section : ";
for (int i = 0; i < sections.length; i++)
if (sections[i] != null)
result += sections[i];
if (result.equals(""))
result += "\nNo sections yet";
result += "\nDescription : " + description;
result += "\nNumber : " + number;
result += "Credit Units : " + creditUnits;
return result;
}
} /* end of Course */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -