Skip to content

Commit

Permalink
add questions as a custom package
Browse files Browse the repository at this point in the history
  • Loading branch information
Forest committed Feb 15, 2024
1 parent 9e3349a commit c5a3d7e
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ComputerScience42SAP.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/nbproject/private" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
17 changes: 10 additions & 7 deletions src/mainpackage/MainClass.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@

/** Required package class namespace */
/**
* Required package class namespace
*/
package mainpackage;

/** Required API imports */
import testing.Tester;

import testing.Tester;
import testing.forest.TestCode;

/**
* MainClass.java - the main class for this project
*
* @author Mr. Wachs
* @since June 2023
*/
public class MainClass
{
public class MainClass {

/**
* Main method for the project
*
*
* @param args the command line arguments
*/
public static void main(String[] args) {
new Tester();
//new Tester();
new TestCode(); // Forest's code
}

}

// <editor-fold>
Expand Down
4 changes: 2 additions & 2 deletions src/testing/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class Tester
*/
public Tester() {
Simulator.header("Mr. Wachs Computer Science testing started...");
new PreCourseContent();
//new PreCourseContent();
new ComputerScience42SAP();
new PostCourseContent();
//new PostCourseContent();
Simulator.saveOutput();
Simulator.header("Mr. Wachs Computer Science testing complete!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ public APUnit01PrimitiveTypes() {
System.out.println("specified type of data. However, the data ");
System.out.print("itself can change (or \"vary\") after the initial ");
System.out.println("declaration. Examples of this are below...");

int age = 17;
final String name = "Forest";

// Variables declared and assigned initial ("starting") values:
boolean a = true;
int b = 0;
Expand Down
33 changes: 33 additions & 0 deletions src/testing/forest/TestCode.java
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();
}
}
}
17 changes: 17 additions & 0 deletions src/testing/forest/questions/Question1.java
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);
}
}
25 changes: 25 additions & 0 deletions src/testing/forest/questions/Question2.java
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));
}
}
58 changes: 58 additions & 0 deletions src/testing/forest/questions/Question3.java
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);


}
}

0 comments on commit c5a3d7e

Please sign in to comment.