lab 9 close #7
This commit is contained in:
54
lab/lab9/Question4/Door.java
Normal file
54
lab/lab9/Question4/Door.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
||||
* Date: 2022-04-21
|
||||
* Description: This is the class of Door.
|
||||
*/
|
||||
|
||||
public class Door {
|
||||
/**
|
||||
* Indicator of whether the door is open or not. Default is closed
|
||||
*/
|
||||
private boolean isOpen;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Door() {
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the door is open or not.
|
||||
*
|
||||
* @return true if the door is open, false otherwise
|
||||
*/
|
||||
public boolean isOpen() {
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the door.
|
||||
*/
|
||||
public void open() {
|
||||
isOpen = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the door.
|
||||
*/
|
||||
public void close() {
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public static void testDoor() {
|
||||
Door d = new Door();
|
||||
System.out.println(d.isOpen() == false);
|
||||
d.close();
|
||||
System.out.println(d.isOpen() == false);
|
||||
d.open();
|
||||
System.out.println(d.isOpen() == true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user