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

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