Skip to content

Commit

Permalink
docs: adding subject and main
Browse files Browse the repository at this point in the history
  • Loading branch information
amin authored and zanninso committed Jul 18, 2024
1 parent d789bcd commit 9a21ca8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
20 changes: 20 additions & 0 deletions subjects/java/checkpoints/monthly-period/ExerciseRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class ExerciseRunner {
public static void main(String[] args) {
MonthlyPeriod MonthlyPeriod = new MonthlyPeriod();

// Test case 1
String startDate1 = "2020-01-01";
String endDate1 = "2023-06-15";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate1, endDate1));

// Test case 2
String startDate2 = "2015-05-20";
String endDate2 = "2015-10-20";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate2, endDate2));

// Test case 3
String startDate3 = "2018-12-25";
String endDate3 = "2021-12-25";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate3, endDate3));
}
}
60 changes: 60 additions & 0 deletions subjects/java/checkpoints/monthly-period/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Monthly Period

### Instructions

Create a class `MonthlyPeriod` that provides a method to calculate the period between two given dates in terms of months and years. The dates will be provided in the format `yyyy-MM-dd`.

In case of any error the method `calculatePeriod` should return `Error`

> 💡 Going to the past is possible!
### Expected Class

```java
import java.time.LocalDate;
import java.time.Period;
import java.time.format.DateTimeFormatter;

public class MonthlyPeriod {
public String calculatePeriod(String startDate, String endDate) {
// Implementation to calculate the period between two dates in months and years
}
}
```
### Usage

Here is a possible `ExerciseRunner.java` to test your class:

```java
public class ExerciseRunner {
public static void main(String[] args) {
MonthlyPeriod MonthlyPeriod = new MonthlyPeriod();

// Test case 1
String startDate1 = "2020-01-01";
String endDate1 = "2023-06-15";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate1, endDate1));

// Test case 2
String startDate2 = "2015-05-20";
String endDate2 = "2015-10-20";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate2, endDate2));

// Test case 3
String startDate3 = "2018-12-25";
String endDate3 = "2021-12-25";
System.out.println("Period: " + MonthlyPeriod.calculatePeriod(startDate3, endDate3));
}
}
```

### Expected Output

```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Period: 3 years and 5 months
Period: 5 months
Period: 3 years
$
```

0 comments on commit 9a21ca8

Please sign in to comment.