Kr Younger před 6 roky
rodič
revize
f7139c23d7
9 změnil soubory, kde provedl 724 přidání a 0 odebrání
  1. 23
    0
      .gitignore
  2. 10
    0
      .vscode/launch.test.json
  3. 12
    0
      README.TXT
  4. 3
    0
      README.md
  5. 88
    0
      WriteIFs.java
  6. 87
    0
      WriteIFsTest.java
  7. 380
    0
      WriteLoops.java
  8. 63
    0
      WriteLoopsTest.java
  9. 58
    0
      package.bluej

+ 23
- 0
.gitignore Zobrazit soubor

1
+# Compiled class file
2
+*.class
3
+
4
+# Log file
5
+*.log
6
+
7
+# BlueJ files
8
+*.ctxt
9
+
10
+# Mobile Tools for Java (J2ME)
11
+.mtj.tmp/
12
+
13
+# Package Files #
14
+*.jar
15
+*.war
16
+*.nar
17
+*.ear
18
+*.zip
19
+*.tar.gz
20
+*.rar
21
+
22
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23
+hs_err_pid*

+ 10
- 0
.vscode/launch.test.json Zobrazit soubor

1
+{
2
+    "run": {
3
+        "default": "",
4
+        "items": []
5
+    },
6
+    "debug": {
7
+        "default": "",
8
+        "items": []
9
+    }
10
+}

+ 12
- 0
README.TXT Zobrazit soubor

1
+------------------------------------------------------------------------
2
+This is the project README file. Here, you should describe your project.
3
+Tell the reader (someone who does not know anything about this project)
4
+all he/she needs to know. The comments should usually include at least:
5
+------------------------------------------------------------------------
6
+
7
+PROJECT TITLE:
8
+PURPOSE OF PROJECT:
9
+VERSION or DATE:
10
+HOW TO START THIS PROJECT:
11
+AUTHORS:
12
+USER INSTRUCTIONS:

+ 3
- 0
README.md Zobrazit soubor

1
+# First Saturday
2
+
3
+see README.TXT

+ 88
- 0
WriteIFs.java Zobrazit soubor

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

+ 87
- 0
WriteIFsTest.java Zobrazit soubor

1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class WriteIFsTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class WriteIFsTest
15
+{
16
+    private static final double _0_5 = 0.5;
17
+    private static final double _0_04 = 0.04;
18
+
19
+    /**
20
+     * Default constructor for test class WriteIFsTest
21
+     */
22
+    public WriteIFsTest()
23
+    {
24
+    }
25
+
26
+    /**
27
+     * Sets up the test fixture.
28
+     *
29
+     * Called before every test case method.
30
+     */
31
+    @Before
32
+    public void setUp()
33
+    {
34
+    }
35
+
36
+    /**
37
+     * Tears down the test fixture.
38
+     *
39
+     * Called after every test case method.
40
+     */
41
+    @After
42
+    public void tearDown()
43
+    {
44
+    }
45
+
46
+    @Test
47
+    public void TestIfs()
48
+    {
49
+        WriteIFs writeIFs1 = new WriteIFs();
50
+        writeIFs1.playerDied(true);
51
+        assertEquals("Game Over!", writeIFs1.ss);
52
+    }
53
+
54
+
55
+    @Test
56
+    public void TestTherm()
57
+    {
58
+        WriteIFs writeIFs1 = new WriteIFs();
59
+        assertEquals("heating", writeIFs1.thermoSTAT(62));
60
+    }
61
+    @Test
62
+    public void TestTherm1()
63
+    {
64
+        WriteIFs writeIFs1 = new WriteIFs();
65
+        assertEquals("cooling", writeIFs1.thermoSTAT(81));
66
+    }
67
+    @Test
68
+    public void TestCheckFuel()
69
+    {
70
+        WriteIFs writeIFs1 = new WriteIFs();
71
+        writeIFs1.playerDied(true);
72
+        assertEquals("Game Over!", writeIFs1.ss);
73
+    }
74
+    @Test
75
+    public void TestFireControl()
76
+    {
77
+        WriteIFs writeIFs1 = new WriteIFs();
78
+        writeIFs1.checkFuel(_0_5);
79
+        assertEquals(0, writeIFs1.x);
80
+        writeIFs1.checkFuel(_0_04);
81
+        assertEquals(99, writeIFs1.x);
82
+    }
83
+
84
+}
85
+
86
+
87
+

+ 380
- 0
WriteLoops.java Zobrazit soubor

1
+import com.sun.org.apache.xpath.internal.SourceTree;
2
+
3
+/**
4
+ * Writeloops get you thinking about how to do different things with loops.
5
+ *
6
+ * @author kyounger
7
+ * @version 1.1
8
+ */
9
+public class WriteLoops {
10
+
11
+    private static final int _3 = 3;
12
+
13
+    public int oneToFive() {
14
+        int w = 0;
15
+
16
+        // Write a FOR loop that counts from 1 to 10.
17
+        for (int i = 1; i <= 5; i++) {
18
+            // calling
19
+            w = w + 1;
20
+            // each time through the loop
21
+        }
22
+
23
+        // this will tell the test how many times the loop executed.
24
+        return w;
25
+    }
26
+
27
+    public int oneToTen() {
28
+        int w = 0;
29
+
30
+        // Write a FOR loop that counts from 1 to 10.
31
+
32
+        // calling
33
+        w = w + 1;
34
+        // each time through the loop
35
+
36
+        return w;
37
+    }
38
+
39
+    public int startAtTwentyOne() {
40
+        int w = 0;
41
+
42
+        // Write a FOR loop that makes 10 iterations, start at 21.
43
+
44
+        // calling
45
+        w = w + 1;
46
+        // each time through the loop
47
+
48
+        return w;
49
+    }
50
+
51
+    public int countDown() {
52
+        int w = 0;
53
+
54
+        // Write a FOR loop that counts down from 100 to 0.
55
+
56
+        // calling
57
+        w = w + 1;
58
+        // each time through the loop
59
+
60
+        return w;
61
+    }
62
+
63
+    public int byTwoTo32() {
64
+        int w = 0;
65
+
66
+        // Write a FOR loop from 0 to 32 by 2s.
67
+
68
+        // calling
69
+        w = w + 1;
70
+        // each time through the loop
71
+
72
+        return w;
73
+    }
74
+
75
+    public int countDownFrom5000() {
76
+        int w = 0;
77
+
78
+        // Write a FOR loop from 1 to less than 5001 by 11s.
79
+
80
+        // calling
81
+        w = w + 1;
82
+        // each time through the loop
83
+
84
+        return w;
85
+    }
86
+
87
+    public int nestedFors() {
88
+        int w = 0;
89
+
90
+        // Write a nested FOR loop(s), where one counts from
91
+        // 0 to less than 20 and the inner one counts from 0 to 4
92
+
93
+        // calling
94
+        w = w + 1;
95
+        // each time through the inner loop
96
+
97
+        return w;
98
+    }
99
+
100
+    public int helloZipCode() {
101
+        int w = 0;
102
+
103
+        // Write a FOR loop that counts from 5 to 105. Put an IF
104
+        // statement inside the loop that checks the
105
+        // loop index counter and if it’s greater than 51,
106
+        // prints “Hello Zipcode” instead of the statement w = w + 1;
107
+
108
+        // calling
109
+        w = w + 1;
110
+        // each time through the inner loop
111
+
112
+        return w;
113
+    }
114
+
115
+    public void simpleLoops() {
116
+        int i = 0;
117
+
118
+        // sample while loop
119
+        while (i <= 5) {
120
+            System.out.println("Eww.");
121
+            i = i + 1;
122
+        }
123
+
124
+        // sample do...while loop
125
+        i = 8;
126
+        do {
127
+            System.out.println("Eww.");
128
+            i = i - 1;
129
+        } while (i > 0);
130
+        // what's the primary difference between them?!?
131
+    }
132
+
133
+    // Write a WHILE loop that checks “gpsCurrentLocation()”
134
+    // and if that is not equal to “Home” then and it calls “driveSomeMore()”.
135
+    // After the loop is done, print “Honey, I’m Home!”
136
+    public int driveHome() {
137
+        int w = 0;
138
+
139
+        // you need to use a .equals for two Strings.
140
+
141
+        // calling
142
+        w = w + 1;
143
+        // each time through the inner loop
144
+
145
+        System.out.println("Honey, I’m Home!");
146
+        return w;
147
+    }
148
+
149
+    // Getting harder...
150
+    // First declare and set “highestScore” to 236. Then set “currentScore” to
151
+    // “gameNextScore()”. Then write a WHILE loop that checks “currentScore”
152
+    // is less than “highestScore” and if it is, adds “currentScore” to
153
+    // "runningScore"
154
+    // and then sets “currentScore” to “gameNextScore()”
155
+    public boolean checkGameScore() {
156
+        int w = 0;
157
+        int highestScore = 236;
158
+        int currentScore = gameNextScore();
159
+        int runningScore = 0;
160
+
161
+        // do your while loop here
162
+
163
+        // do your ifs here
164
+
165
+        // calling
166
+        w = w + 1;
167
+        // each time through the inner loop
168
+
169
+        return w > 3;
170
+    }
171
+
172
+    // Rewrite the previous WHILE loop as a DO..WHILE loop.
173
+    // Notice how the “runningScore” variable usage is different.
174
+    public boolean checkGameScoreDoWhile() {
175
+        int w = 0;
176
+        int highestScore = 236;
177
+        int currentScore = gameNextScore();
178
+        int runningScore = 0;
179
+
180
+        // do your while loop here
181
+
182
+        // do your ifs here
183
+
184
+        // calling
185
+        w = w + 1;
186
+        // each time through the inner loop
187
+
188
+        return w > 3;
189
+    }
190
+
191
+    // Write a WHILE loop that checks “serverIsRunning()” and if true
192
+    // calls “waitFor(5)” After the loop, write an IF and check “serverIsRunning()”
193
+    // is false, and if so, call “sendEmergencyText(“Help!”, adminPhoneNumber)”
194
+    // and also calls “tryServerRestart()”
195
+    public int checkServerStatus() {
196
+        int w = 0;
197
+        String adminPhoneNumber = "+1 202 456 1111"
198
+        // calling
199
+        w = w + 1;
200
+        // each time through the inner loop
201
+
202
+        return w;
203
+    }
204
+
205
+    // Declare an “int” i. Set i to 7.
206
+    // Write a WHILE loop that checks “i” is less than 50,
207
+    // and if it is, add 7 to “i”
208
+    public int loop50by7() {
209
+        int w = 0;
210
+
211
+        // calling
212
+        w = w + 1;
213
+        // each time through the inner loop
214
+
215
+        return w;
216
+    }
217
+
218
+    // Foo is method that add the first 7 factors of three together and prints
219
+    // out the sum of them all.
220
+    public int foo() {
221
+        int w = 0;
222
+        // this is an array of ints. it is of length 7 (from 0 -> 6)
223
+        int[] threes_array = { 3, 6, 9, 12, 15, 18, 21 };
224
+        int sumOfThrees = 0;
225
+
226
+        // this is a so called Enhanced for loop
227
+        for (int index : threes_array) {
228
+            sumOfThrees = sumOfThrees + threes_array[index];
229
+            // calling
230
+            w = w + 1;
231
+            // each time through the inner loop
232
+        }
233
+        System.out.print("The Sum is ");
234
+        System.out.println(sumOfThrees);
235
+
236
+        return w;
237
+    }
238
+
239
+    // Ponder this: can all FOR loops be rewritten as WHILE loops?
240
+    // rewrite the loop inside of "foo()" as a standard for loop
241
+    // with 'i' as its index variable.
242
+    public int rewriteFooAsFor() {
243
+        int w = 0;
244
+        int sumOfThrees = 0;
245
+
246
+        // calling
247
+        w = w + 1;
248
+        // each time through the inner loop
249
+
250
+        System.out.print("The Sum is ");
251
+        System.out.println(sumOfThrees);
252
+
253
+        return w;
254
+    }
255
+
256
+    // Ponder this: can all WHILE loops be rewritten as FOR loops?
257
+    // rewrite the loop inside of "foo()" as a 'while' loop
258
+    public int rewriteFooAsWhile() {
259
+        int w = 0;
260
+        int sumOfThrees = 0;
261
+
262
+        // calling
263
+        w = w + 1;
264
+        // each time through the inner loop
265
+
266
+        System.out.print("The Sum is ");
267
+        System.out.println(sumOfThrees);
268
+
269
+        return w;
270
+    }
271
+
272
+    // Declare a boolean “yardNeedsMowed” and initialize to true.
273
+    // Write WHILE loop that checks for “isSummer()”.
274
+    // inside the loop, write an IF that checks “yardNeedsMowed” and if true calls
275
+    // “yellAtJuniorToMowLawn()”
276
+    // After loop, call
277
+    // “sendJuniorBackToSchool(onTime)”
278
+    public int manageYardAndJunior() {
279
+        int w = 0;
280
+        boolean onTime = true;
281
+
282
+        // ADD YOUR CODE here.
283
+
284
+        // be sure to call
285
+        w = w + 1;
286
+        // each time inside the loop
287
+
288
+        return w;
289
+    }
290
+
291
+    String voteTallies[] = { "Lincoln", "Washington", "Adams",
292
+    "Lincoln", "Washington", "Adams", "Lincoln", "Washington", "Adams",
293
+    "Lincoln", "Washington", "Adams", "Roosevelt"
294
+    };
295
+    // Given an array voteTallies[], write a FOR loop that prints out each value in
296
+    // the array.
297
+    public int tallyVote1() {
298
+        int w = 0;
299
+        int numberOfVotes = voteTallies.length;
300
+
301
+        // calling
302
+        w = w + 1;
303
+        // each time through the inner loop
304
+
305
+        return w;
306
+    }
307
+
308
+    // Given an array voteTallies[], write a WHILE loop that prints out each value
309
+    // in the array. You should declare and use an index “idx” to keep track of
310
+    // where you are.
311
+    public int tallyVote2() {
312
+        int w = 0;
313
+        int numberOfVotes = voteTallies.length;
314
+
315
+        // calling
316
+        w = w + 1;
317
+        // each time through the inner loop
318
+
319
+        return w;
320
+    }
321
+
322
+    /**
323
+     * CONGRATS, you've written all the code. Does it all pass their tests?!?
324
+     * 
325
+     * 
326
+     * If not, why not? :-)
327
+     * 
328
+     * 
329
+     */
330
+
331
+    /**
332
+     * IGNORE the CODER behind the CURTAIN. These are the support routines to make
333
+     * all the examples interesting.
334
+     */
335
+    // instance variables - replace the example below with your own
336
+    private int x;
337
+
338
+    /**
339
+     * Constructor for objects of class WriteLoops
340
+     */
341
+    public WriteLoops() {
342
+        // initialise instance variables
343
+        x = 0;
344
+    }
345
+
346
+    private int gps = 0;
347
+
348
+    private String gpsCurrentLocation() {
349
+        if (this.gps > 5) {
350
+            return "Home";
351
+        }
352
+        return "Not Home";
353
+    }
354
+
355
+    private void driveSomeMore() {
356
+        this.gps += 1;
357
+    }
358
+
359
+    private int scr = 31;
360
+
361
+    private int gameNextScore() {
362
+        return this.scr = this.scr + ThreadLocalRandom.current().nextInt(20, 99 + 1);
363
+    }
364
+
365
+    private boolean isSummer = () -> {
366
+        int i = 0;
367
+        return () -> {
368
+            i = i + 1;
369
+            return (i >= _3);
370
+        };
371
+    };
372
+
373
+    private void sendEmergencyText(String mesg, String phone) {}
374
+    private void tryServerRestart(String mesg, String phone) {}
375
+    int serverStatus = 5;
376
+    private boolean serverIsRunning() {return (serverStatus > 20);}
377
+    private void waitFor(int interval) {serverStatus += interval;}
378
+
379
+
380
+}

+ 63
- 0
WriteLoopsTest.java Zobrazit soubor

1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class WriteLoopsTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class WriteLoopsTest
15
+{
16
+    /**
17
+     * Default constructor for test class WriteLoopsTest
18
+     */
19
+    public WriteLoopsTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+
43
+
44
+    @Test
45
+    public void TestOneToFive()
46
+    {
47
+        WriteLoops writeLoo1 = new WriteLoops();
48
+        assertEquals(5, writeLoo1.oneToFive());
49
+    }
50
+    @Test
51
+    public void TestOneToTen()
52
+    {
53
+        WriteLoops writeLoo1 = new WriteLoops();
54
+        assertEquals(5, writeLoo1.oneToTen());
55
+    }
56
+    @Test
57
+    public void TestStartAtTwentyOne()
58
+    {
59
+        WriteLoops writeLoo1 = new WriteLoops();
60
+        assertEquals(5, writeLoo1.startAtTwentyOne());
61
+    }
62
+}
63
+

+ 58
- 0
package.bluej Zobrazit soubor

1
+#BlueJ package file
2
+dependency1.from=WriteIFsTest
3
+dependency1.to=WriteIFs
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=722
6
+editor.fx.0.width=800
7
+editor.fx.0.x=90
8
+editor.fx.0.y=152
9
+objectbench.height=101
10
+objectbench.width=694
11
+package.divider.horizontal=0.5630522088353414
12
+package.divider.vertical=0.8625954198473282
13
+package.editor.height=671
14
+package.editor.width=1139
15
+package.editor.x=112
16
+package.editor.y=89
17
+package.frame.height=844
18
+package.frame.width=1265
19
+package.numDependencies=1
20
+package.numTargets=4
21
+package.showExtends=true
22
+package.showUses=true
23
+project.charset=UTF-8
24
+readme.height=58
25
+readme.name=@README
26
+readme.width=47
27
+readme.x=10
28
+readme.y=10
29
+target1.height=110
30
+target1.name=WriteLoopsTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=180
34
+target1.x=170
35
+target1.y=330
36
+target2.association=WriteLoopsTest
37
+target2.height=110
38
+target2.name=WriteLoops
39
+target2.showInterface=false
40
+target2.type=ClassTarget
41
+target2.width=180
42
+target2.x=140
43
+target2.y=360
44
+target3.association=WriteIFsTest
45
+target3.height=110
46
+target3.name=WriteIFs
47
+target3.showInterface=false
48
+target3.type=ClassTarget
49
+target3.width=170
50
+target3.x=150
51
+target3.y=130
52
+target4.height=110
53
+target4.name=WriteIFsTest
54
+target4.showInterface=false
55
+target4.type=UnitTestTargetJunit4
56
+target4.width=170
57
+target4.x=180
58
+target4.y=100