-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Forest
committed
Feb 15, 2024
1 parent
9e3349a
commit c5a3d7e
Showing
8 changed files
with
149 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package testing.forest; | ||
|
||
import testing.forest.questions.*; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
/* | ||
* TestCode.java - Running some code for testing purposes | ||
* | ||
* @Author Forest | ||
*/ | ||
public class TestCode { | ||
public TestCode() { | ||
initializeQuestions(); | ||
} | ||
|
||
private void initializeQuestions() { | ||
try { | ||
Class<?>[] questionClasses = { | ||
Question1.class, | ||
Question2.class, | ||
Question3.class | ||
}; | ||
|
||
for (Class<?> questionClass : questionClasses) { | ||
Constructor<?> constructor = questionClass.getDeclaredConstructor(); | ||
constructor.newInstance(); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package testing.forest.questions; | ||
|
||
import io.Simulator; | ||
|
||
public class Question1 { | ||
public Question1() { | ||
Simulator.header("Question 1"); | ||
int a = 5; | ||
int b = 2; | ||
double c = 3.0; | ||
Simulator.code("int a = 5;"); | ||
Simulator.code("int b = 2;"); | ||
Simulator.code("double c = 3.0;"); | ||
Simulator.code("System.out.println(5 + a / b * c -1);"); | ||
System.out.println(5 + a / b * c -1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package testing.forest.questions; | ||
|
||
import io.Simulator; | ||
|
||
import java.util.Random; | ||
|
||
public class Question2 { | ||
Random random = new Random(); | ||
public Question2() { | ||
Simulator.header("Question 2"); | ||
|
||
String[] words = {"hello", "world", "java", "programming", "language", "computer", "science", "software", "engineering"}; | ||
for (int i = 0; i < 5; i++) { | ||
processWords(words[random.nextInt(words.length)], words[random.nextInt(words.length)]); | ||
} | ||
} | ||
|
||
public static void processWords(String word1, String word2) { | ||
String str1 = word1.substring(0, 2); | ||
String str2 = word2.substring(word2.length() - 1); | ||
String result = str2 + str1; | ||
int index = result.indexOf(str2); | ||
System.out.println(result.indexOf(str2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package testing.forest.questions; | ||
|
||
import io.Simulator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Question3 { | ||
|
||
List<Integer> rn1List = new ArrayList<>(); | ||
List<Integer> rn2List = new ArrayList<>(); | ||
List<Integer> rn3List = new ArrayList<>(); | ||
List<Integer> rn4List = new ArrayList<>(); | ||
List<Integer> rn5List = new ArrayList<>(); | ||
|
||
public Question3() { | ||
Simulator.header("Question 3"); | ||
Simulator.comment("Witch of the following statments assigns a random int between 25 and 60, inclusive, to `rn`?"); | ||
|
||
Simulator.code("int rn = (int) (Math.random() * 25) + 36;"); | ||
Simulator.code("int rn = (int) (Math.random() * 25) + 60;"); | ||
Simulator.code("int rn = (int) (Math.random() * 26) + 60;"); | ||
Simulator.code("int rn = (int) (Math.random() * 36) + 25;"); | ||
Simulator.code("int rn = (int) (Math.random() * 60) + 25;"); | ||
|
||
Simulator.comment("Run each 100 times."); | ||
|
||
for (int i = 0; i < 100; i++) { | ||
int rn1 = (int) (Math.random() * 25) + 36; | ||
int rn2 = (int) (Math.random() * 25) + 60; | ||
int rn3 = (int) (Math.random() * 26) + 60; | ||
int rn4 = (int) (Math.random() * 36) + 25; | ||
int rn5 = (int) (Math.random() * 60) + 25; | ||
|
||
rn1List.add(rn1); | ||
rn2List.add(rn2); | ||
rn3List.add(rn3); | ||
rn4List.add(rn4); | ||
rn5List.add(rn5); | ||
} | ||
|
||
// Check if the results are within the range | ||
boolean rn1InRange = rn1List.stream().allMatch(num -> num >= 25 && num <= 60); | ||
boolean rn2InRange = rn2List.stream().allMatch(num -> num >= 25 && num <= 60); | ||
boolean rn3InRange = rn3List.stream().allMatch(num -> num >= 25 && num <= 60); | ||
boolean rn4InRange = rn4List.stream().allMatch(num -> num >= 25 && num <= 60); | ||
boolean rn5InRange = rn5List.stream().allMatch(num -> num >= 25 && num <= 60); | ||
|
||
// Output the results | ||
Simulator.output("rn1List: " + rn1List + ", all in range: " + rn1InRange, true); | ||
Simulator.output("rn2List: " + rn2List + ", all in range: " + rn2InRange, true); | ||
Simulator.output("rn3List: " + rn3List + ", all in range: " + rn3InRange, true); | ||
Simulator.output("rn4List: " + rn4List + ", all in range: " + rn4InRange, true); | ||
Simulator.output("rn5List: " + rn5List + ", all in range: " + rn5InRange, true); | ||
|
||
|
||
} | ||
} |