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

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