diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f2a078 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +.gradle/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..f76a02c --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Autograding Example: Java +This example project is written in Java, and tested with Gradle/JUnit. + +### The assignment +The tests are currently failing because of an output mismatch. Fixing the `System.out.println` in the main method will make the tests green. + +### Setup command +N/A + +### Run command +`gradle test` + +### Notes +- The JDK is installed on GitHub Actions machines, so you're also able to directly invoke `javac`, `java`, or any other CLI command included in the JDK. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..7cccf6c --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'java' +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation('org.junit.jupiter:junit-jupiter:5.6.0') +} + +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..c831873 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,13 @@ + + +public class Main { + + public static void main(final String[] args) { + PigLatin sim = new PigLatin(); + //sim.tester(); + } + + + +} + diff --git a/src/main/java/PigLatin.java b/src/main/java/PigLatin.java new file mode 100644 index 0000000..07fa007 --- /dev/null +++ b/src/main/java/PigLatin.java @@ -0,0 +1,48 @@ +import java.io.File; // Import the File class +import java.io.FileNotFoundException; // Import this class to handle errors +import java.util.Scanner; // Import the Scanner class to read text files + +public class PigLatin { + + public void tester() { + // String[] lines = loadStrings("words.txt"); + String[] lines = new String[8]; + try{ + File myFile = new File("words.txt"); + Scanner myReader = new Scanner(myFile); + int counter = 0; + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + lines[counter] = data; + counter++; + } + myReader.close(); + } + catch (FileNotFoundException e) { + System.out.println("An error occurred."); + e.printStackTrace(); + } + System.out.println("there are " + lines.length + " lines"); + for (int i = 0 ; i < lines.length; i++) { + System.out.println(pigLatin(lines[i])); + } + } + public int findFirstVowel(String sWord) { + //precondition: sWord is a valid String of length greater than 0. + //postcondition: returns the position of the first vowel in sWord. If there are no vowels, returns -1 + // your code goes here + return -1; + } + + public String pigLatin(String sWord) { + //precondition: sWord is a valid String of length greater than 0 + //postcondition: returns the pig latin equivalent of sWord + // more code should go here + if(findFirstVowel(sWord) == -1) { + return sWord + "ay"; + } + else { + return "ERROR!"; + } + } +}//end PigLatin class diff --git a/src/test/java/PigLatinTester.java b/src/test/java/PigLatinTester.java new file mode 100644 index 0000000..c014015 --- /dev/null +++ b/src/test/java/PigLatinTester.java @@ -0,0 +1,44 @@ + + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import java.io.*; + +public class PigLatinTester { + + @Test + public void caseR(){ + PigLatin sim = new PigLatin(); + assertEquals("eastbay", sim.pigLatin("beast")); + assertEquals("oughday", sim.pigLatin("dough")); + assertEquals("appyhay", sim.pigLatin("happy")); + } + + @Test + public void y(){ + PigLatin sim = new PigLatin(); + assertEquals("tryay", sim.pigLatin("try")); + } + @Test + public void vowels(){ + PigLatin sim = new PigLatin(); + assertEquals("eagleway", sim.pigLatin("eagle")); + } + @Test + public void q(){ + PigLatin sim = new PigLatin(); + assertEquals("estionquay", sim.pigLatin("question")); + } + @Test + public void multipleConsonant(){ + PigLatin sim = new PigLatin(); + assertEquals("arstay", sim.pigLatin("star")); + assertEquals("eethray", sim.pigLatin("three")); + } + +} diff --git a/src/words.txt b/src/words.txt new file mode 100644 index 0000000..548c2fa --- /dev/null +++ b/src/words.txt @@ -0,0 +1,8 @@ +beast +dough +happy +question +star +three +eagle +try