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

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