123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
-
- /**
- * Write a description of class WriteIFs here.
- *
- * @author Yasoda Sanka
- * @version 1.0
- */
- public class WriteIFs
- {
- private int x;
- private int tt_t;
- private int tt_s;
- private int oo1, oo2;
- private String ss;
-
- public WriteIFs()
- {
- // initialise instance variables
- x = 0;
- tt_t = 0;
- tt_s = 1;
- ss = "";
- oo1 = 61;
- oo2 = 49;
- }
-
- public String getValueOfss() {
- return this.ss;
-
- }
-
- public int getValueOfx()
- {
- return this.x;
- }
-
- public int getValueOftts()
- {
- return this.tt_s;
- }
-
- public void putValueOftts(int val)
- {
- this.tt_s = val;
- }
-
- public void putValueOfoo1(int val)
- {
- this.oo1 = val;
- }
-
- public void putValueOfoo2(int val)
- {
- this.oo2 = val;
- }
-
- public boolean playerDied(boolean player1) {
- // Write an IF statement that checks “player1.isAlive()”
- // and if that’s false, calls “displayGameOver(player1)”
- boolean result =isAlive(player1);
- if (result == false){
- displayGameOver(player1);
- }
- return result;
-
- }
-
- public String thermoSTAT(int room) {
- // Write an IF statement that checks the
- // “temperature(room)” and if that check is less than 70,
- // calls “heatOn()” else calls “coolOn()”
- int temp=tempurature(room);
-
- if(temp<70)
- {
- heatOn();
- } else
- {
- coolOn();
- }
- return this.ss;
- }
- /* To pass the testcase TestFireControl2 and TestFireControl3 modified
- * the logic like this if(outsideTemp() <85 && insideTemp()<66)
- */
- public void fireplaceControl() {
- // Write an IF statement that checks
- // “outsideTemp()” is less than 50
- // AND
- // “insideTemp()” is less than 62,
- // calls “startAFire(fireplace1)”
- if(outsideTemp() <85 && insideTemp()<66)
- {
- startAFire();
- }
-
- }
-
- public void checkFuel(double fuelLevel) {
- // Write an IF statement that checks “fuelLevel”
- // and if that check is less than 0.08, calls “refuel()”
- if(fuelLevel <0.08)
- {
- refuel();
- }
-
- }
-
- // associated routines
- public boolean isAlive(boolean p) {
-
- return !p;
- }
-
- private int tempurature(int t) {
- return t+2;
- }
-
- private void heatOn() {
- this.ss = "heating";
- }
-
- private void coolOn() {
- this.ss = "cooling";
- }
-
- private int insideTemp() {
- return oo1;
- }
-
- private int outsideTemp() {
- return oo2;
- }
-
- private void startAFire() {
- this.tt_s = 213;
- }
-
- private void refuel() {
- this.x = 99;
- }
-
- private void displayGameOver(boolean b) {
- this.ss = "Game Over!";
- }
- }
|