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

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