Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-classroom[bot] authored Jan 7, 2025
0 parents commit 357ce97
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
.gradle/
14 changes: 14 additions & 0 deletions README.md
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.
18 changes: 18 additions & 0 deletions build.gradle
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"
}
}
13 changes: 13 additions & 0 deletions src/main/java/Main.java
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();
}



}

48 changes: 48 additions & 0 deletions src/main/java/PigLatin.java
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
44 changes: 44 additions & 0 deletions src/test/java/PigLatinTester.java
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"));
}

}
8 changes: 8 additions & 0 deletions src/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
beast
dough
happy
question
star
three
eagle
try

0 comments on commit 357ce97

Please sign in to comment.