This commit is contained in:
2022-03-17 18:18:06 +08:00
parent 52c53c5be7
commit 6bf672bd5b
10 changed files with 631 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
/*
* 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);
}
}