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 8, 2025
0 parents commit b5cf42c
Show file tree
Hide file tree
Showing 6 changed files with 128 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"
}
}
12 changes: 12 additions & 0 deletions src/main/java/Main.java
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();
}


}

49 changes: 49 additions & 0 deletions src/main/java/PalindromeChecker.java
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;
}
}
33 changes: 33 additions & 0 deletions src/test/java/PalindromeTester.java
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"));
}
}

0 comments on commit b5cf42c

Please sign in to comment.