From 3ceb7322eb5dddb9aa111e23a2667154ad2590a5 Mon Sep 17 00:00:00 2001 From: amin Date: Mon, 1 Jul 2024 15:15:00 +0100 Subject: [PATCH] docs: adding subject and main --- .../age-finder/ExerciseRunner.java | 17 ++++++ .../java/checkpoints/age-finder/README.md | 56 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 subjects/java/checkpoints/age-finder/ExerciseRunner.java create mode 100644 subjects/java/checkpoints/age-finder/README.md diff --git a/subjects/java/checkpoints/age-finder/ExerciseRunner.java b/subjects/java/checkpoints/age-finder/ExerciseRunner.java new file mode 100644 index 000000000..6862bbd0e --- /dev/null +++ b/subjects/java/checkpoints/age-finder/ExerciseRunner.java @@ -0,0 +1,17 @@ +public class ExerciseRunner { + public static void main(String[] args) { + AgeFinder AgeFinder = new AgeFinder(); + + // Test case 1 + String date1 = "2000-01-01"; + System.out.println("Age: " + AgeFinder.calculateAge(date1)); + + // Test case 2 + String date2 = "1990-06-15"; + System.out.println("Age: " + AgeFinder.calculateAge(date2)); + + // Test case 3 + String date3 = "2010-12-25"; + System.out.println("Age: " + AgeFinder.calculateAge(date3)); + } +} \ No newline at end of file diff --git a/subjects/java/checkpoints/age-finder/README.md b/subjects/java/checkpoints/age-finder/README.md new file mode 100644 index 000000000..d4902636c --- /dev/null +++ b/subjects/java/checkpoints/age-finder/README.md @@ -0,0 +1,56 @@ +## Age Finder + +### Instructions + +Create a class `AgeFinder` that provides a method to calculate the age from a given date. The date will be provided in the format `yyyy-MM-dd`. + +In case of any error the method `calculateAge` should return `-1` + +### Expected Class + +```java +import java.time.LocalDate; +import java.time.Period; +import java.time.format.DateTimeFormatter; + +public class AgeFinder { + public int calculateAge(String date) { + // Implementation to calculate the age from the given date + } +} +``` + +### Usage + +Here is a possible `ExerciseRunner.java` to test your class: + +```java +public class ExerciseRunner { + public static void main(String[] args) { + AgeFinder AgeFinder = new AgeFinder(); + + // Test case 1 + String date1 = "2000-01-01"; + System.out.println("Age: " + AgeFinder.calculateAge(date1)); + + // Test case 2 + String date2 = "1990-06-15"; + System.out.println("Age: " + AgeFinder.calculateAge(date2)); + + // Test case 3 + String date3 = "2010-12-25"; + System.out.println("Age: " + AgeFinder.calculateAge(date3)); + } +} +``` + +### Expected Output + +```shell +$ javac *.java -d build +$ java -cp build ExerciseRunner +Age: 24 +Age: 34 +Age: 13 +$ +```