diff --git a/subjects/java/checkpoints/html-validator/ExerciseRunner.java b/subjects/java/checkpoints/html-validator/ExerciseRunner.java new file mode 100644 index 000000000..1e01c215c --- /dev/null +++ b/subjects/java/checkpoints/html-validator/ExerciseRunner.java @@ -0,0 +1,21 @@ +public class ExerciseRunner { + public static void main(String[] args) { + HTMLValidator validator = new HTMLValidator(); + + // Test case 1: Valid HTML + String html1 = "

Hello, World!

"; + System.out.println("Is HTML valid? " + validator.validateHTML(html1)); // Expected output: true + + // Test case 2: Invalid HTML (missing closing tag) + String html2 = "

Hello, World!"; + System.out.println("Is HTML valid? " + validator.validateHTML(html2)); // Expected output: false + + // Test case 3: Invalid HTML (incorrect nesting) + String html3 = "

Hello, World!

"; + System.out.println("Is HTML valid? " + validator.validateHTML(html3)); // Expected output: false + + // Test case 4: Valid HTML with multiple tags + String html4 = "

This is a bold word and this is italic.

"; + System.out.println("Is HTML valid? " + validator.validateHTML(html4)); // Expected output: true + } +} \ No newline at end of file diff --git a/subjects/java/checkpoints/html-validator/README.md b/subjects/java/checkpoints/html-validator/README.md new file mode 100644 index 000000000..c30aa39bf --- /dev/null +++ b/subjects/java/checkpoints/html-validator/README.md @@ -0,0 +1,55 @@ +## HTML Validator + +### Instructions + +Create a class `HTMLValidator` that provides a method to validate whether a given HTML string is correctly formatted. The method should support a few basic HTML tags (``, ``, `
`, `

`, ``, ``, `

`, `

`). If the HTML is valid, the method should return `true`. If the HTML is invalid, the method should return `false`. + +### Expected Class + +```java +public class HTMLValidator { + public boolean validateHTML(String html) { + // Implementation to validate if the given HTML is correctly formatted + } +} +``` + +### Usage + +Here is a possible `ExerciseRunner.java` to test your class: + +```java +public class ExerciseRunner { + public static void main(String[] args) { + HTMLValidator validator = new HTMLValidator(); + + // Test case 1: Valid HTML + String html1 = "

Hello, World!

"; + System.out.println("Is HTML valid? " + validator.validateHTML(html1)); // Expected output: true + + // Test case 2: Invalid HTML (missing closing tag) + String html2 = "

Hello, World!"; + System.out.println("Is HTML valid? " + validator.validateHTML(html2)); // Expected output: false + + // Test case 3: Invalid HTML (incorrect nesting) + String html3 = "

Hello, World!

"; + System.out.println("Is HTML valid? " + validator.validateHTML(html3)); // Expected output: false + + // Test case 4: Valid HTML with multiple tags + String html4 = "

This is a bold word and this is italic.

"; + System.out.println("Is HTML valid? " + validator.validateHTML(html4)); // Expected output: true + } +} +``` + +### Expected Output + +```shell +$ javac *.java -d build +$ java -cp build ExerciseRunner +Is HTML valid? true +Is HTML valid? false +Is HTML valid? false +Is HTML valid? true +$ +```