-
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
Showing
1,215 changed files
with
57,583 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-java |
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,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>tkt</groupId> | ||
<artifactId>Part08_01.Cubes</artifactId> | ||
<name>Part08_01.Cubes</name> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>fi.helsinki.cs.tmc</groupId> | ||
<artifactId>edu-test-utils</artifactId> | ||
<version>0.4.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</project> |
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,20 @@ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Cubes { | ||
|
||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
while (true){ | ||
String input = scanner.nextLine(); | ||
if (input.equals("end")){ | ||
break; | ||
} | ||
int numInput = Integer.valueOf(input); | ||
int cube = numInput * numInput * numInput; | ||
System.out.println(cube); | ||
} | ||
|
||
} | ||
} |
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,91 @@ | ||
|
||
import fi.helsinki.cs.tmc.edutestutils.MockStdio; | ||
import fi.helsinki.cs.tmc.edutestutils.Points; | ||
import fi.helsinki.cs.tmc.edutestutils.ReflectionUtils; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import org.junit.*; | ||
import static org.junit.Assert.*; | ||
|
||
@Points("08-01") | ||
public class CubestTest { | ||
|
||
@Rule | ||
public MockStdio io = new MockStdio(); | ||
|
||
@Test | ||
public void test() { | ||
String[][] inputs = {{"8", "3", "123", "end"}, {"9", "end"}, {"16", "32", "end"}}; | ||
|
||
for (int i = 0; i < inputs.length; i++) { | ||
check(inputs[i]); | ||
} | ||
} | ||
|
||
private void check(String... input) { | ||
int oldOut = io.getSysOut().length(); | ||
|
||
List<Integer> expected = new ArrayList<>(); | ||
String in = ""; | ||
for (int i = 0; i < input.length; i++) { | ||
try { | ||
int number = Integer.valueOf(input[i]); | ||
expected.add(number * number * number); | ||
} catch (Exception e) { | ||
|
||
} | ||
|
||
in += input[i] + "\n"; | ||
} | ||
|
||
io.setSysIn(in); | ||
callMain(Cubes.class); | ||
String out = io.getSysOut().substring(oldOut); | ||
|
||
assertTrue("When the input is:\n" + in + "\nyou are not printing anything!", out.length() > 0); | ||
|
||
String[] prints = takePrints(out); | ||
for (String print : prints) { | ||
int number = -1; | ||
try { | ||
number = Integer.valueOf(print); | ||
} catch (NumberFormatException e) { | ||
continue; | ||
} | ||
|
||
if (!expected.contains(number)) { | ||
fail("Input:\n" + in + "\nWas not expecting \"" + number + "\" to be printed, but it was.\nThe output was:\n" + out); | ||
} | ||
|
||
expected.remove(Integer.valueOf(number)); | ||
} | ||
|
||
if (!expected.isEmpty()) { | ||
for (Integer expectedNumber : expected) { | ||
fail("Input:\n" + in + "\n\n Expected number: \"" + expectedNumber + "\", the output was: \"" + out + "\"\n"); | ||
} | ||
|
||
} | ||
} | ||
|
||
private void callMain(Class kl) { | ||
try { | ||
kl = ReflectionUtils.newInstanceOfClass(kl); | ||
String[] t = null; | ||
String x[] = new String[0]; | ||
Method m = ReflectionUtils.requireMethod(kl, "main", x.getClass()); | ||
ReflectionUtils.invokeMethod(Void.TYPE, m, null, (Object) x); | ||
} catch (NoSuchElementException e) { | ||
fail("Your program tried to read too much input. Be sure to use the nextLine() method to read input!"); | ||
} catch (Throwable e) { | ||
fail("public static void main(String[] args) method of the " + kl + " class has disappeared " | ||
+ "or something else unexpected occurred, more information: " + e); | ||
} | ||
} | ||
|
||
private static String[] takePrints(String str) { | ||
return str.split("\\s+"); | ||
} | ||
} |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
....Cubes/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
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 @@ | ||
Cubes.class |
1 change: 1 addition & 0 deletions
1
...01.Cubes/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
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 @@ | ||
/home/austin/NetBeansProjects/mooc-java-programming-ii/part08-Part08_01.Cubes/src/main/java/Cubes.java |
1 change: 1 addition & 0 deletions
1
...arget/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
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 @@ | ||
CubestTest.class |
1 change: 1 addition & 0 deletions
1
.../target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
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 @@ | ||
/home/austin/NetBeansProjects/mooc-java-programming-ii/part08-Part08_01.Cubes/src/test/java/CubestTest.java |
Empty file.
Empty file.
Binary file not shown.
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,2 @@ | ||
--- | ||
sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-java |
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,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>tkt</groupId> | ||
<artifactId>Part08_02.AverageOfPositiveNumbers</artifactId> | ||
<name>Part08_02.AverageOfPositiveNumbers</name> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>fi.helsinki.cs.tmc</groupId> | ||
<artifactId>edu-test-utils</artifactId> | ||
<version>0.4.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>tmc</id> | ||
<name>TMC repo</name> | ||
<url>https://maven.mooc.fi/releases</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
part08-Part08_02.AverageOfPositiveNumbers/src/main/java/AverageOfPositiveNumbers.java
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,40 @@ | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class AverageOfPositiveNumbers { | ||
|
||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
ArrayList<Integer> numbers = new ArrayList<>(); | ||
|
||
int sum = 0; | ||
|
||
while (true){ | ||
int input = Integer.valueOf(scanner.nextLine()); | ||
if (input == 0){ | ||
break; | ||
} | ||
|
||
if (input > 0){ | ||
numbers.add(input); | ||
} | ||
} | ||
|
||
for (int i : numbers){ | ||
sum += i; | ||
} | ||
|
||
if (numbers.isEmpty()){ | ||
System.out.println("Cannot calculate the average"); | ||
} else { | ||
System.out.println((1.0 * sum / numbers.size())); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
} |
61 changes: 61 additions & 0 deletions
61
part08-Part08_02.AverageOfPositiveNumbers/src/test/java/AverageOfPositiveNumbersTest.java
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,61 @@ | ||
|
||
import fi.helsinki.cs.tmc.edutestutils.MockStdio; | ||
import fi.helsinki.cs.tmc.edutestutils.Points; | ||
import fi.helsinki.cs.tmc.edutestutils.ReflectionUtils; | ||
import java.lang.reflect.Method; | ||
import org.junit.*; | ||
import static org.junit.Assert.*; | ||
|
||
@Points("08-02") | ||
public class AverageOfPositiveNumbersTest { | ||
|
||
@Rule | ||
public MockStdio io = new MockStdio(); | ||
|
||
@Test(timeout = 1000) | ||
public void test1() { | ||
test("0\n", "nnot", "0", "1", "-1"); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void test2() { | ||
test("1\n2\n0\n", "1.5", "0"); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void test3() { | ||
test("-1\n3\n0\n", "3.0", "1"); | ||
} | ||
|
||
@Test(timeout = 1000) | ||
public void test4() { | ||
test("1\n1\n1\n0\n", "1.0", "0.3", "0.7"); | ||
} | ||
|
||
public void test(String input, String expected, String... notExpected) { | ||
|
||
int oldOut = io.getSysOut().length(); | ||
io.setSysIn(input); | ||
callMain(AverageOfPositiveNumbers.class); | ||
String out = io.getSysOut().substring(oldOut); | ||
|
||
assertTrue("When input was:\n" + input + ", the expected out put was:\n" + expected + "\nOutput was not found.", out.contains(expected)); | ||
for (String unexpected : notExpected) { | ||
assertFalse("When input was:\n" + input + ", output shouldn't contain:\n" + unexpected + "", out.contains(unexpected)); | ||
} | ||
} | ||
|
||
private void callMain(Class kl) { | ||
try { | ||
kl = ReflectionUtils.newInstanceOfClass(kl); | ||
String[] t = null; | ||
String x[] = new String[0]; | ||
Method m = ReflectionUtils.requireMethod(kl, "main", x.getClass()); | ||
ReflectionUtils.invokeMethod(Void.TYPE, m, null, (Object) x); | ||
} catch (Throwable e) { | ||
fail("Something unexpected happened. The public static void main(String[] args) method of '" + kl + "' class has disappeared \n" | ||
+ "or your program crashed because of an exception. More info: " + e); | ||
} | ||
} | ||
|
||
} |
Binary file added
BIN
+1.56 KB
part08-Part08_02.AverageOfPositiveNumbers/target/classes/AverageOfPositiveNumbers.class
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...umbers/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
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 @@ | ||
AverageOfPositiveNumbers.class |
1 change: 1 addition & 0 deletions
1
...eNumbers/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
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 @@ | ||
/home/austin/NetBeansProjects/mooc-java-programming-ii/part08-Part08_02.AverageOfPositiveNumbers/src/main/java/AverageOfPositiveNumbers.java |
1 change: 1 addition & 0 deletions
1
...arget/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
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 @@ | ||
AverageOfPositiveNumbersTest.class |
1 change: 1 addition & 0 deletions
1
.../target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
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 @@ | ||
/home/austin/NetBeansProjects/mooc-java-programming-ii/part08-Part08_02.AverageOfPositiveNumbers/src/test/java/AverageOfPositiveNumbersTest.java |
Empty file.
Empty file.
Binary file added
BIN
+3.38 KB
...Part08_02.AverageOfPositiveNumbers/target/test-classes/AverageOfPositiveNumbersTest.class
Binary file not shown.
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,2 @@ | ||
--- | ||
sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-java |
Oops, something went wrong.