-
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
0 parents
commit 357ce97
Showing
7 changed files
with
147 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 @@ | ||
build/ | ||
.gradle/ |
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,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. |
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,18 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0') | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
} | ||
} |
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,13 @@ | ||
|
||
|
||
public class Main { | ||
|
||
public static void main(final String[] args) { | ||
PigLatin sim = new PigLatin(); | ||
//sim.tester(); | ||
} | ||
|
||
|
||
|
||
} | ||
|
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,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 |
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,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")); | ||
} | ||
|
||
} |
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,8 @@ | ||
beast | ||
dough | ||
happy | ||
question | ||
star | ||
three | ||
eagle | ||
try |