Restore
This commit is contained in:
10
Labs/Lab4/Lab4_2230026071/Question2/.classpath
Normal file
10
Labs/Lab4/Lab4_2230026071/Question2/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Labs/Lab4/Lab4_2230026071/Question2/.project
Normal file
17
Labs/Lab4/Lab4_2230026071/Question2/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
BIN
Labs/Lab4/Lab4_2230026071/Question2/bin/Start.class
Normal file
BIN
Labs/Lab4/Lab4_2230026071/Question2/bin/Start.class
Normal file
Binary file not shown.
BIN
Labs/Lab4/Lab4_2230026071/Question2/bin/Student.class
Normal file
BIN
Labs/Lab4/Lab4_2230026071/Question2/bin/Student.class
Normal file
Binary file not shown.
17
Labs/Lab4/Lab4_2230026071/Question2/src/Start.java
Normal file
17
Labs/Lab4/Lab4_2230026071/Question2/src/Start.java
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
//the check() method should be static, because the main function is static, therefore it cannot accesses check() as check() is non-static.
|
||||
//but anyway, check() could be a non-static method when re-creating a non-static Start class to access it.
|
||||
public static String check(Student student) {
|
||||
if(student.isSleeping() == true) return "sweet dreams";
|
||||
else return "need coffee";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Student.testStudent();
|
||||
Student s = new Student(1234567890);
|
||||
System.out.println(check(s));
|
||||
}
|
||||
|
||||
}
|
||||
36
Labs/Lab4/Lab4_2230026071/Question2/src/Student.java
Normal file
36
Labs/Lab4/Lab4_2230026071/Question2/src/Student.java
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
public class Student {
|
||||
//instance variables
|
||||
private int ID;
|
||||
private boolean sleeping;
|
||||
|
||||
//constructor
|
||||
public Student(int ID) {
|
||||
this.ID = ID;
|
||||
this.sleeping = false;
|
||||
}
|
||||
|
||||
//methods
|
||||
public int getID() {return this.ID;}
|
||||
|
||||
public boolean isSleeping() {return this.sleeping;}
|
||||
|
||||
public void fallAsleep() {this.sleeping = true;}
|
||||
|
||||
public void wakeUp() {this.sleeping = false;}
|
||||
|
||||
//test
|
||||
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(); // should do nothing because the student is already sleeping
|
||||
System.out.println(s.isSleeping() == true);
|
||||
s.wakeUp();
|
||||
System.out.println(s.isSleeping() == false);
|
||||
s.wakeUp(); // should do nothing because the student is already awake
|
||||
System.out.println(s.isSleeping() == false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user