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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Write a description of class WriteIFs here.
  3. *
  4. * @author William Brown
  5. * @version 1.0 10/21/2018
  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 WriteIFs()
  15. {
  16. // initialise instance variables
  17. x = 0;
  18. tt_t = 0;
  19. tt_s = 1;
  20. ss = "";
  21. oo1 = 61;
  22. oo2 = 49;
  23. }
  24. public void playerDied(boolean player1) {
  25. // Write an IF statement that checks “player1.isAlive()”
  26. if(player1 == true){
  27. displayGameOver(player1);
  28. }
  29. // and if that’s false, calls “displayGameOver(player1)”
  30. }
  31. public String thermoSTAT(int room) {
  32. // Write an IF statement that checks the
  33. // “temperature(room)” and if that check is less than 70,
  34. // calls “heatOn()” else calls “coolOn()”
  35. if(tempurature(room) < 70){
  36. heatOn();
  37. } else{
  38. coolOn();
  39. }
  40. return this.ss;
  41. }
  42. public void fireplaceControl(Object fireplace1) {
  43. // Write an IF statement that checks
  44. // “outsideTemp()” is less than 50
  45. // AND
  46. // “insideTemp()” is less than 62,
  47. // calls “startAFire(fireplace1)”
  48. if(outsideTemp() < 50 || insideTemp() < 62){
  49. startAFire(fireplace1);
  50. }
  51. }
  52. public void checkFuel(double fuelLevel) {
  53. // Write an IF statement that checks “fuelLevel”
  54. // and if that check is less than 0.08, calls “refuel()”
  55. if(fuelLevel < 0.08){
  56. refuel();
  57. }
  58. }
  59. /**
  60. * Pay no attention to the code below this point.
  61. *
  62. *
  63. * instance variables
  64. int x;
  65. int tt_t;
  66. int tt_s;
  67. int oo1, oo2;
  68. String ss;
  69. * Constructor for objects of class WriteIFs
  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. }