83 lines
1.7 KiB
Java
83 lines
1.7 KiB
Java
/*
|
|
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
|
* Date: 2022-03-10
|
|
* Description: Student class
|
|
*/
|
|
|
|
public class Student {
|
|
|
|
/*
|
|
* Student's ID number
|
|
*/
|
|
private int ID;
|
|
|
|
/*
|
|
* whether the student is currently sleeping or not, default is false
|
|
*/
|
|
private boolean sleeping;
|
|
|
|
/**
|
|
* Constructor. Initialize the ID number and sleeping status as false.
|
|
*
|
|
* @param ID, the ID number of the student
|
|
*/
|
|
public Student(int ID) {
|
|
this.ID = ID;
|
|
this.sleeping = false;
|
|
}
|
|
|
|
/**
|
|
* Getter of the ID number.
|
|
*
|
|
* @return the ID number of the student
|
|
*/
|
|
public int getID() {
|
|
return this.ID;
|
|
}
|
|
|
|
/**
|
|
* Identify whether the student is sleeping or not.
|
|
*
|
|
* @return true if the student is sleeping, false otherwise
|
|
*/
|
|
public boolean isSleeping() {
|
|
return this.sleeping;
|
|
}
|
|
|
|
/**
|
|
* Make the student fall in sleep.
|
|
*
|
|
* @return void
|
|
*/
|
|
public void fallAsleep() {
|
|
this.sleeping = true;
|
|
}
|
|
|
|
/**
|
|
* Walkup the student.
|
|
*
|
|
* @return void
|
|
*/
|
|
public void wakeUp() {
|
|
this.sleeping = false;
|
|
}
|
|
|
|
/**
|
|
* Test student class.
|
|
*/
|
|
public static void testStudent() {
|
|
Student s = new Student(1234567890);
|
|
|
|
System.out.println(s.getID() == 1234567890);
|
|
System.out.println(s.isSleeping() == false);
|
|
s.fallAsleep();
|
|
System.out.println(s.isSleeping() == true);
|
|
s.fallAsleep();
|
|
System.out.println(s.isSleeping() == true);
|
|
s.wakeUp();
|
|
System.out.println(s.isSleeping() == false);
|
|
s.wakeUp();
|
|
System.out.println(s.isSleeping() == false);
|
|
}
|
|
}
|