Lab 4
This commit is contained in:
30
lab/lab4/Question2/Start.java
Normal file
30
lab/lab4/Question2/Start.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Explain:
|
||||
* The check method is static because it is do not need to create an Start object.
|
||||
*/
|
||||
|
||||
public class Start {
|
||||
public static void main(String[] args) {
|
||||
Student.testStudent();
|
||||
|
||||
Student stu = new Student(123);
|
||||
System.out.println(check(stu) == "need coffee");
|
||||
stu.fallAsleep();
|
||||
System.out.println(check(stu) == "sweet dreams");
|
||||
}
|
||||
|
||||
/**
|
||||
* check student sleeping. If student is sleeping, return "sweet dreams", if
|
||||
* not, return "need coffee".
|
||||
*
|
||||
* @param stu. Student object
|
||||
* @return String.
|
||||
*/
|
||||
public static String check(Student stu) {
|
||||
if (stu.isSleeping()) {
|
||||
return "sweet dreams";
|
||||
} else {
|
||||
return "need coffee";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user