Skip to content

Commit c4534f5

Browse files
committed
no message
1 parent c9a0352 commit c4534f5

File tree

11 files changed

+913
-1
lines changed

11 files changed

+913
-1
lines changed

Lab3/src/academy/pocu/comp2500/lab3/3.md

+723
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public enum DeviceType {
4+
SPRINKLER,
5+
DRAINER
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public class Drainer extends SmartDevice implements IWaterDetectable, IDrainable{
4+
private static int DISPLACEMENT = 7;
5+
private Planter planter;
6+
7+
private int displacementStartStandard;
8+
9+
public Drainer(int displacementStartStandard) {
10+
this.displacementStartStandard = displacementStartStandard;
11+
}
12+
13+
public int getDisplacementStartStandard() {
14+
return this.displacementStartStandard;
15+
}
16+
17+
@Override
18+
public void onTick() {
19+
detect(planter.getWaterAmount());
20+
}
21+
22+
@Override
23+
public void drain(Planter planter) {
24+
25+
}
26+
27+
@Override
28+
public void detect(int waterLevel) {
29+
if (waterLevel >= this.displacementStartStandard)) {
30+
drain(planter);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public interface IDrainable {
4+
void drain(Planter planter);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public interface ISprayable {
4+
void spray(Planter planter);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public interface IWaterDetectable {
4+
void detect(final int waterLevel);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
import java.util.ArrayList;
4+
5+
public class Planter {
6+
private int waterAmount;
7+
ArrayList<SmartDevice> devices = new ArrayList<>();
8+
9+
public Planter(int waterAmount) {
10+
this.waterAmount = waterAmount;
11+
}
12+
13+
public void setWaterAmount(int waterAmount) {
14+
this.waterAmount = waterAmount;
15+
}
16+
17+
public int getWaterAmount() {
18+
return waterAmount;
19+
}
20+
21+
public void installSmartDevice(SmartDevice device) {
22+
23+
}
24+
25+
26+
27+
public void tick() {
28+
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public class Schedule {
4+
private int sprinklerStartTick;
5+
private int tickCounter;
6+
7+
public Schedule(int sprinklerStartTick, int tickCounter) {
8+
this.sprinklerStartTick = sprinklerStartTick;
9+
this.tickCounter = tickCounter;
10+
}
11+
12+
public int getSprinklerStartTick() {
13+
return this.sprinklerStartTick;
14+
}
15+
16+
public int getTickCounter() {
17+
return this.tickCounter;
18+
}
19+
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
public abstract class SmartDevice {
4+
protected int currentTick;
5+
6+
public boolean isOn() {
7+
return false;
8+
}
9+
10+
public void onTick() {
11+
12+
}
13+
14+
public int getTicksSinceLastUpdate() {
15+
return -1;
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package academy.pocu.comp2500.lab8;
2+
3+
import java.util.ArrayDeque;
4+
import java.util.ArrayList;
5+
import java.util.Queue;
6+
7+
public class Sprinkler extends SmartDevice implements ISprayable {
8+
private ArrayList<Schedule> schedules = new ArrayList<>();
9+
private static int sprayedVolume = 15;
10+
private Planter planter;
11+
private int counter;
12+
13+
public void addSchedule(Schedule schedule) {
14+
this.schedules.add(schedule);
15+
}
16+
17+
@Override
18+
public void spray(Planter planter) {
19+
if (isOn()) {
20+
planter.setWaterAmount(sprayedVolume);
21+
}
22+
}
23+
24+
@Override
25+
public int getTicksSinceLastUpdate() {
26+
return super.currentTick;
27+
}
28+
29+
@Override
30+
public boolean isOn() {
31+
if (schedules.size() == 0) {
32+
return false;
33+
}
34+
35+
if (schedules.get(0).getSprinklerStartTick() <= super.currentTick) {
36+
if (schedules.get(0).getTickCounter() > counter) {
37+
counter++;
38+
39+
return true;
40+
} else {
41+
schedules.remove(0);
42+
for (var schedule : schedules) {
43+
if (schedule.getSprinklerStartTick() < counter) {
44+
schedules.remove(schedule);
45+
} else {
46+
break;
47+
}
48+
}
49+
super.currentTick = 1;
50+
counter = 0;
51+
return false;
52+
}
53+
}
54+
return true;
55+
}
56+
57+
@Override
58+
public void onTick() {
59+
super.currentTick++;
60+
if (isOn()) {
61+
spray(planter);
62+
}
63+
64+
}
65+
66+
}

Lab8/src/academy/pocu/comp2500/lab8/Program.java Lab8/src/academy/pocu/comp2500/lab8Program/Program.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package academy.pocu.comp2500.lab8;
1+
package academy.pocu.comp2500.lab8Program;
22

33
public class Program {
44

0 commit comments

Comments
 (0)