Pārlūkot izejas kodu

checkpointing my work

Jose Bedolla 6 gadus atpakaļ
vecāks
revīzija
8a9c85942e
3 mainītis faili ar 60 papildinājumiem un 23 dzēšanām
  1. 32
    17
      WriteIFs.java
  2. 6
    0
      WriteIFsTest.java
  3. 22
    6
      WriteLoops.java

+ 32
- 17
WriteIFs.java Parādīt failu

5
  * @author (your name)
5
  * @author (your name)
6
  * @version (a version number or a date)
6
  * @version (a version number or a date)
7
  */
7
  */
8
+
8
 public class WriteIFs
9
 public class WriteIFs
9
 {
10
 {
11
+   int x;
12
+   int tt_t;
13
+   int tt_s;
14
+   int oo1, oo2;
15
+   String ss;
10
  
16
  
11
     public void playerDied(boolean player1) {
17
     public void playerDied(boolean player1) {
12
         // Write an IF statement that checks “player1.isAlive()” 
18
         // Write an IF statement that checks “player1.isAlive()” 
13
         // and if that’s false, calls “displayGameOver(player1)”
19
         // and if that’s false, calls “displayGameOver(player1)”
20
+        if(isAlive(true))
21
+        {
22
+           System.out.println(player1);
23
+        } 
24
+            else 
25
+                {
26
+                    displayGameOver(player1);
27
+                }
14
      
28
      
15
     }
29
     }
16
     
30
     
18
         // Write an IF statement that checks the 
32
         // Write an IF statement that checks the 
19
         // “temperature(room)” and if that check is less than 70, 
33
         // “temperature(room)” and if that check is less than 70, 
20
         // calls “heatOn()” else calls “coolOn()”
34
         // calls “heatOn()” else calls “coolOn()”
35
+        if(temperature(room)<70)
36
+        {
37
+            heatOn();
38
+        }
39
+        else {
40
+            coolOn();
41
+        }
21
 
42
 
22
-
23
-        
24
         return this.ss;
43
         return this.ss;
25
     }
44
     }
26
 
45
 
30
         // AND 
49
         // AND 
31
         // “insideTemp()” is less than 62, 
50
         // “insideTemp()” is less than 62, 
32
         // calls “startAFire(fireplace1)”
51
         // calls “startAFire(fireplace1)”
52
+        if((outsideTemp() < 50) || (insideTemp()<62))
53
+        {
54
+            startAFire(fireplace1);
55
+        }
56
+        
33
 
57
 
34
     }
58
     }
35
 
59
 
36
     public void checkFuel(double fuelLevel) {
60
     public void checkFuel(double fuelLevel) {
37
         // Write an IF statement that checks “fuelLevel” 
61
         // Write an IF statement that checks “fuelLevel” 
38
         // and if that check is less than 0.08, calls “refuel()”
62
         // and if that check is less than 0.08, calls “refuel()”
63
+        if(fuelLevel < 0.08)
64
+        {
65
+            refuel();
66
+        }
39
 
67
 
40
     }
68
     }
41
 
69
 
42
 
70
 
43
-    
44
-    /**
45
-     *  Pay no attention to the code below this point.
46
-     * 
47
-     * 
48
-     * instance variables
49
-     * / 
50
-   int x;
51
-   int tt_t;
52
-   int tt_s;
53
-   int oo1, oo2;
54
-   String ss;
55
-
56
-
57
   /**
71
   /**
58
    * Constructor for objects of class WriteIFs
72
    * Constructor for objects of class WriteIFs
59
    */
73
    */
70
 
84
 
71
     // associated routines
85
     // associated routines
72
     public boolean isAlive(boolean p) {
86
     public boolean isAlive(boolean p) {
87
+    
73
         return !p;
88
         return !p;
74
     }
89
     }
75
-    private int tempurature(int t) {
90
+    private int temperature(int t) {
76
         return t+2;
91
         return t+2;
77
     }
92
     }
78
     private void heatOn() {
93
     private void heatOn() {

+ 6
- 0
WriteIFsTest.java Parādīt failu

13
  */
13
  */
14
 public class WriteIFsTest
14
 public class WriteIFsTest
15
 {
15
 {
16
+   int x;
17
+   int tt_t;
18
+   int tt_s;
19
+   int oo1, oo2;
20
+   String ss;
21
+   
16
     private static final double _0_5 = 0.5;
22
     private static final double _0_5 = 0.5;
17
     private static final double _0_04 = 0.04;
23
     private static final double _0_04 = 0.04;
18
 
24
 

+ 22
- 6
WriteLoops.java Parādīt failu

18
     public int oneToFive() {
18
     public int oneToFive() {
19
         int w = 0;
19
         int w = 0;
20
 
20
 
21
-        // Write a FOR loop that counts from 1 to 10.
21
+        // Write a FOR loop that counts from 5 to 10.
22
             // calling
22
             // calling
23
-            w = w + 1;
23
+            for(int i =5; i < 10; i++)
24
+            {
25
+                w = w +1;
26
+            }
27
+            
24
             // each time through the loop
28
             // each time through the loop
25
 
29
 
26
         // this will tell the test how many times the loop executed.
30
         // this will tell the test how many times the loop executed.
32
 
36
 
33
         // Write a FOR loop that counts from 1 to 10.
37
         // Write a FOR loop that counts from 1 to 10.
34
         // calling
38
         // calling
35
-        w = w + 1;
39
+                   for(int i =0; i < 10; i++)
40
+            {
41
+                w = w +1;
42
+            }
36
         // each time through the loop
43
         // each time through the loop
37
         
44
         
38
         return w;
45
         return w;
43
 
50
 
44
         // Write a FOR loop that makes 10 iterations, start at 21.
51
         // Write a FOR loop that makes 10 iterations, start at 21.
45
         // calling
52
         // calling
46
-        w = w + 1;
53
+            for(int i =21; i < 32; i++)
54
+            {
55
+                w = w +1;
56
+            }
47
         // each time through the loop
57
         // each time through the loop
48
         
58
         
49
         return w;
59
         return w;
54
 
64
 
55
         // Write a FOR loop that counts down from 100 to 0.
65
         // Write a FOR loop that counts down from 100 to 0.
56
         // calling
66
         // calling
57
-        w = w + 1;
67
+            for(int i =100; i > 0; i--)
68
+            {
69
+                w = w +1;
70
+            }
58
         // each time through the loop
71
         // each time through the loop
59
         
72
         
60
         return w;
73
         return w;
65
 
78
 
66
         // Write a FOR loop from 0 to 32 by 2s.
79
         // Write a FOR loop from 0 to 32 by 2s.
67
         // calling
80
         // calling
68
-        w = w + 1;
81
+        for(int i = 1; i <= 32; i+=2)
82
+        {
83
+            w = w + 1;
84
+        }
69
         // each time through the loop
85
         // each time through the loop
70
         return w;
86
         return w;
71
     }
87
     }