-
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 b5cf42c
Showing
6 changed files
with
128 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,12 @@ | ||
|
||
|
||
public class Main { | ||
|
||
public static void main(final String[] args) { | ||
PalindromeChecker sim = new PalindromeChecker(); | ||
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,49 @@ | ||
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 PalindromeChecker { | ||
public void tester() | ||
{ | ||
//String lines[] = loadStrings("palindromes.txt"); | ||
String[] lines = new String[6]; | ||
try{ | ||
File myFile = new File("palindromes.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++) | ||
{ | ||
if(palindrome(lines[i])==true) | ||
{ | ||
System.out.println(lines[i] + " IS a palindrome."); | ||
} | ||
else | ||
{ | ||
System.out.println(lines[i] + " is NOT a palindrome."); | ||
} | ||
} | ||
} | ||
public boolean palindrome(String word) | ||
{ | ||
//your code here | ||
return false; | ||
} | ||
public String reverse(String str) | ||
{ | ||
String sNew = new String(); | ||
//your code here | ||
return sNew; | ||
} | ||
} |
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,33 @@ | ||
|
||
|
||
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 PalindromeTester { | ||
|
||
@Test | ||
public void sentences () { | ||
PalindromeChecker sim = new PalindromeChecker(); | ||
assertEquals(true, sim.palindrome("Madam, I'm Adam!")); | ||
assertEquals(true, sim.palindrome("A Man! A Plan! A Canal! Panama!")); | ||
} | ||
@Test | ||
public void space(){ | ||
PalindromeChecker sim = new PalindromeChecker(); | ||
assertEquals(true, sim.palindrome("nurses run")); | ||
} | ||
|
||
@Test | ||
public void word(){ | ||
PalindromeChecker sim = new PalindromeChecker(); | ||
assertEquals(false, sim.palindrome("test")); | ||
assertEquals(true, sim.palindrome("rotator")); | ||
assertEquals(false, sim.palindrome("rewriter")); | ||
} | ||
} |