📄 module.java
字号:
import java.util.*;
/**
* A class to represent a module.
* It contains a module title and a list of studnts on the module
* It is intended to be used in a GUI example
*
* @author Ian Bradley
* @version 10/04/2007
*/
public class Module
{
private String moduleName;
private ArrayList<Student> students;
/**
* Constructor for objects of class Module
*/
public Module(String moduleName)
{
this. moduleName = moduleName;
students = new ArrayList<Student>();
}
/**
* getter for module name
*
* @return the name of the module
*/
public String getModuleName()
{
return moduleName;
}
/**
* add a student to the module
*
* @param name the student's name
* @param id the student's id
*/
public String addStudent(String name, String id)
{
if (name.equals(""))
return "Error - Empty name field\n";
else
if (id.equals(""))
return "Error - Empty id field\n";
students.add( new Student(name,id) );
return name + " " + id + " added to module " + moduleName;
}
/**
* gets list of students on module
*
* @return the list of students
*/
public String getAllStudents()
{
if ( students.size() > 0 )
{
String allStudents = "";
for ( Student s : students)
{
allStudents = allStudents + s.getName() + " " + s.getID() + "\n";
}
return allStudents;
}
return "Empty Module";
}
public String searchByName(String name)
{
for ( Student s : students )
{
if ( s.getName().equals(name))
return name + " is on module " + moduleName + "\n";
}
return name + " is NOT on module " + moduleName + "\n";
}
public String deleteFromModule(String name)
{
int index = 0;
for ( Student s : students )
{
if ( s.getName().equals(name))
{
students.remove(index);
return name + " removed from module " + moduleName + "\n";
}
index++;
}
return name + " NOT found on module " + moduleName + "\n";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -