Restore
This commit is contained in:
10
Labs/Lab4/Lab4_2230026071/Question4/.classpath
Normal file
10
Labs/Lab4/Lab4_2230026071/Question4/.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/Question4/.project
Normal file
17
Labs/Lab4/Lab4_2230026071/Question4/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question4</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/Question4/bin/Chicken.class
Normal file
BIN
Labs/Lab4/Lab4_2230026071/Question4/bin/Chicken.class
Normal file
Binary file not shown.
BIN
Labs/Lab4/Lab4_2230026071/Question4/bin/Start.class
Normal file
BIN
Labs/Lab4/Lab4_2230026071/Question4/bin/Start.class
Normal file
Binary file not shown.
36
Labs/Lab4/Lab4_2230026071/Question4/src/Chicken.java
Normal file
36
Labs/Lab4/Lab4_2230026071/Question4/src/Chicken.java
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
public class Chicken {
|
||||
//instance variables
|
||||
private double weight;
|
||||
private boolean sleeping;
|
||||
|
||||
//constructor
|
||||
public Chicken(double weight) {
|
||||
this.sleeping = true;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
//methods
|
||||
public double getWeight() {return this.weight;}
|
||||
|
||||
public boolean isSleeping() {return this.sleeping;}
|
||||
|
||||
public void fallAsleep() {this.sleeping = true;}
|
||||
|
||||
public void wakeUp() {this.sleeping = false;}
|
||||
|
||||
//test
|
||||
public static void testChicken() {
|
||||
Chicken c = new Chicken(2.3);
|
||||
System.out.println(c.getWeight() == 2.3);
|
||||
System.out.println(c.isSleeping() == true);
|
||||
c.wakeUp();
|
||||
System.out.println(c.isSleeping() == false);
|
||||
c.wakeUp(); // should do nothing because the chicken is already awake
|
||||
System.out.println(c.isSleeping() == false);
|
||||
c.fallAsleep();
|
||||
System.out.println(c.isSleeping() == true);
|
||||
c.fallAsleep(); // should do nothing because the chicken is already sleeping
|
||||
System.out.println(c.isSleeping() == true);
|
||||
}
|
||||
}
|
||||
16
Labs/Lab4/Lab4_2230026071/Question4/src/Start.java
Normal file
16
Labs/Lab4/Lab4_2230026071/Question4/src/Start.java
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
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(Chicken chicken) {
|
||||
if(chicken.isSleeping() == true) return "sweet dreams";
|
||||
else return "need coffee";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Chicken.testChicken();
|
||||
Chicken c = new Chicken(2.3);
|
||||
System.out.println(check(c));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user