docs: adding subject and main

This commit is contained in:
amin 2024-05-21 01:48:54 +01:00 committed by zanninso
parent 6a28cbea5a
commit d2d9e09f06
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,19 @@
public class ExerciseRunner {
public static void main(String[] args) {
// Example of a very short project
ProjectTime shortProject = new ProjectTime("2023-05-14 09:00", "2023-05-14 09:30");
System.out.println("Short Project Total Logged Time: " + shortProject.getHoursLogged()); // Should be "30 m"
// Example of an overnight project
ProjectTime overnightProject = new ProjectTime("2023-05-14 20:00", "2023-05-15 08:00");
System.out.println("Overnight Project Total Logged Time: " + overnightProject.getHoursLogged()); // Should be "12 h"
// Example of a full day project
ProjectTime fullDayProject = new ProjectTime("2023-05-14 00:00", "2023-05-15 00:00");
System.out.println("Full Day Project Total Logged Time: " + fullDayProject.getHoursLogged()); // Should be "24 h"
// Example with incorrect format
ProjectTime errorProject = new ProjectTime("2023-05-14", "2023-05-15 08:00");
System.out.println("Error Project Total Logged Time: " + errorProject.getHoursLogged()); // Should handle error or indicate incorrect format
}
}

View File

@ -0,0 +1,72 @@
## TimeTracker
### Instructions
Write a `ProjectTime` class to track the duration of a project using start and end times. You will be asked to add getter and setter methods for the `startTime` and `endTime` attributes. When you set one of them, you must update the `hoursLogged` attribute. The `hoursLogged` getter should output the hours in the following format:
- Less than 120 minutes: `hoursLogged` minutes
- Less than 120 hours: `hoursLogged` hours
- Less than 120 days: `hoursLogged` days
- More than 120 days: `hoursLogged` months
If there is any error, the number of `hoursLogged` should be handled accordingly.
> 💡 The `hoursLogged` shouldn't be a negative number except -1 in case of errors.
### Expected Functions
```java
public class ProjectTime {
private String startTime;
private String endTime;
private float hoursLogged;
public ProjectTime(String start, String end);
public void setStartTime();
public void setEndTime();
public String getStartTime();
public String getEndTime();
public String getHoursLogged();
}
```
### Usage
Here is a possible `ExerciseRunner.java` to test your function :
```java
public class ExerciseRunner {
public static void main(String[] args) {
// Example of a very short project
ProjectTime shortProject = new ProjectTime("2023-05-14 09:00", "2023-05-14 09:30");
System.out.println("Short Project Total Logged Time: " + shortProject.getHoursLogged()); // Should be "30 m"
// Example of an overnight project
ProjectTime overnightProject = new ProjectTime("2023-05-14 20:00", "2023-05-15 08:00");
System.out.println("Overnight Project Total Logged Time: " + overnightProject.getHoursLogged()); // Should be "12 h"
// Example of a full day project
ProjectTime fullDayProject = new ProjectTime("2023-05-14 00:00", "2023-05-15 00:00");
System.out.println("Full Day Project Total Logged Time: " + fullDayProject.getHoursLogged()); // Should be "24 h"
// Example with incorrect format
ProjectTime errorProject = new ProjectTime("2023-05-14", "2023-05-15 08:00");
System.out.println("Error Project Total Logged Time: " + errorProject.getHoursLogged()); // Should handle error or indicate incorrect format
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Short Project Total Logged Time: 30 m
Overnight Project Total Logged Time: 12 h
Full Day Project Total Logged Time: 24 h
Error Project Total Logged Time: -1
$
```