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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Write a description of class WriteIFs here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class WriteIFs
  8. {
  9. // initialise instance variables
  10. int x = 0;
  11. int tt_t = 0;
  12. int tt_s = 1;
  13. String ss = "";
  14. int oo1 = 61;
  15. int oo2 = 49;
  16. public void playerDied(boolean player1) {
  17. // Write an IF statement that checks “player1.isAlive()”
  18. // and if that’s false, calls “displayGameOver(player1)”
  19. if(isAlive(player1)==false) {
  20. displayGameOver(player1);
  21. }
  22. }
  23. public String thermoSTAT(int room) {
  24. // Write an IF statement that checks the
  25. // “temperature(room)” and if that check is less than 70,
  26. // calls “heatOn()” else calls “coolOn()”
  27. if(tempurature(room)<70){
  28. heatOn();
  29. } else {
  30. coolOn();
  31. }
  32. return this.ss;
  33. }
  34. public void fireplaceControl(Object fireplace1) {
  35. // Write an IF statement that checks
  36. // “outsideTemp()” is less than 50
  37. // AND
  38. // “insideTemp()” is less than 62,
  39. // calls “startAFire(fireplace1)”
  40. if(outsideTemp()<50 || insideTemp()<62){
  41. startAFire(fireplace1);
  42. }
  43. }
  44. public void checkFuel(double fuelLevel) {
  45. // Write an IF statement that checks “fuelLevel”
  46. // and if that check is less than 0.08, calls “refuel()”
  47. if (fuelLevel<0.08){
  48. refuel();
  49. }
  50. }
  51. /**
  52. * Pay no attention to the code below this point.
  53. *
  54. *
  55. * instance variables
  56. * /
  57. int x;
  58. int tt_t;
  59. int tt_s;
  60. int oo1, oo2;
  61. String ss;
  62. /**
  63. * Constructor for objects of class WriteIFs
  64. */
  65. public WriteIFs()
  66. {
  67. // initialise instance variables
  68. x = 0;
  69. tt_t = 0;
  70. tt_s = 1;
  71. ss = "";
  72. oo1 = 61;
  73. oo2 = 49;
  74. }
  75. // associated routines
  76. public boolean isAlive(boolean p) {
  77. return !p;
  78. }
  79. private int tempurature(int t) {
  80. return t+2;
  81. }
  82. private void heatOn() {
  83. this.ss = "heating";
  84. }
  85. private void coolOn() {
  86. this.ss = "cooling";
  87. }
  88. private int insideTemp() {
  89. return oo1;
  90. }
  91. private int outsideTemp() {
  92. return oo2;
  93. }
  94. private void startAFire(Object o) {
  95. this.tt_s = 213;
  96. }
  97. private void refuel() {
  98. this.x = 99;
  99. }
  100. private void displayGameOver(boolean b) {
  101. this.ss = "Game Over!";
  102. }
  103. }