Write bunch of java to solve a series of requirements and pass a series of tests to prove your code works the way it should.

WriteIFs.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Write a description of class WriteIFs here.
  3. *
  4. * @author Yasoda Sanka
  5. * @version 1.0
  6. */
  7. public class WriteIFs
  8. {
  9. private int x;
  10. private int tt_t;
  11. private int tt_s;
  12. private int oo1, oo2;
  13. private String ss;
  14. public WriteIFs()
  15. {
  16. // initialise instance variables
  17. x = 0;
  18. tt_t = 0;
  19. tt_s = 1;
  20. ss = "";
  21. oo1 = 61;
  22. oo2 = 49;
  23. }
  24. public String getValueOfss() {
  25. return this.ss;
  26. }
  27. public int getValueOfx()
  28. {
  29. return this.x;
  30. }
  31. public int getValueOftts()
  32. {
  33. return this.tt_s;
  34. }
  35. public void putValueOftts(int val)
  36. {
  37. this.tt_s = val;
  38. }
  39. public void putValueOfoo1(int val)
  40. {
  41. this.oo1 = val;
  42. }
  43. public void putValueOfoo2(int val)
  44. {
  45. this.oo2 = val;
  46. }
  47. public boolean playerDied(boolean player1) {
  48. // Write an IF statement that checks “player1.isAlive()”
  49. // and if that’s false, calls “displayGameOver(player1)”
  50. boolean result =isAlive(player1);
  51. if (result == false){
  52. displayGameOver(player1);
  53. }
  54. return result;
  55. }
  56. public String thermoSTAT(int room) {
  57. // Write an IF statement that checks the
  58. // “temperature(room)” and if that check is less than 70,
  59. // calls “heatOn()” else calls “coolOn()”
  60. int temp=tempurature(room);
  61. if(temp<70)
  62. {
  63. heatOn();
  64. } else
  65. {
  66. coolOn();
  67. }
  68. return this.ss;
  69. }
  70. /* To pass the testcase TestFireControl2 and TestFireControl3 modified
  71. * the logic like this if(outsideTemp() <85 && insideTemp()<66)
  72. */
  73. public void fireplaceControl() {
  74. // Write an IF statement that checks
  75. // “outsideTemp()” is less than 50
  76. // AND
  77. // “insideTemp()” is less than 62,
  78. // calls “startAFire(fireplace1)”
  79. if(outsideTemp() <85 && insideTemp()<66)
  80. {
  81. startAFire();
  82. }
  83. }
  84. public void checkFuel(double fuelLevel) {
  85. // Write an IF statement that checks “fuelLevel”
  86. // and if that check is less than 0.08, calls “refuel()”
  87. if(fuelLevel <0.08)
  88. {
  89. refuel();
  90. }
  91. }
  92. // associated routines
  93. public boolean isAlive(boolean p) {
  94. return !p;
  95. }
  96. private int tempurature(int t) {
  97. return t+2;
  98. }
  99. private void heatOn() {
  100. this.ss = "heating";
  101. }
  102. private void coolOn() {
  103. this.ss = "cooling";
  104. }
  105. private int insideTemp() {
  106. return oo1;
  107. }
  108. private int outsideTemp() {
  109. return oo2;
  110. }
  111. private void startAFire() {
  112. this.tt_s = 213;
  113. }
  114. private void refuel() {
  115. this.x = 99;
  116. }
  117. private void displayGameOver(boolean b) {
  118. this.ss = "Game Over!";
  119. }
  120. }