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

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