|
1 | 1 | import java.time.LocalDate; |
2 | 2 | import java.time.LocalDateTime; |
| 3 | +import java.time.format.DateTimeFormatter; |
3 | 4 |
|
4 | 5 | class AppointmentScheduler { |
5 | 6 | public LocalDateTime schedule(String appointmentDateDescription) { |
6 | | - throw new UnsupportedOperationException("Please implement the AppointmentScheduler.schedule() method"); |
| 7 | + // throw new UnsupportedOperationException("Please implement the AppointmentScheduler.schedule() method"); |
| 8 | + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss"); |
| 9 | + LocalDateTime date = LocalDateTime.parse(appointmentDateDescription, formatter); |
| 10 | + |
| 11 | + DateTimeFormatter printer = DateTimeFormatter.ofPattern("yyyy, MM, dd, HH, mm, ss"); |
| 12 | + printer.format(date); |
| 13 | + return LocalDateTime.of(date.getYear(), date.getMonth(), date.getDayOfMonth(), date.getHour(), date.getMinute(), date.getSecond()); |
7 | 14 | } |
8 | 15 |
|
9 | 16 | public boolean hasPassed(LocalDateTime appointmentDate) { |
10 | | - throw new UnsupportedOperationException("Please implement the AppointmentScheduler.hasPassed() method"); |
| 17 | + // throw new UnsupportedOperationException("Please implement the AppointmentScheduler.hasPassed() method"); |
| 18 | + return appointmentDate.isBefore(LocalDateTime.now()); |
11 | 19 | } |
12 | 20 |
|
13 | 21 | public boolean isAfternoonAppointment(LocalDateTime appointmentDate) { |
14 | | - throw new UnsupportedOperationException("Please implement the AppointmentScheduler.isAfternoonAppointment() method"); |
| 22 | + // throw new UnsupportedOperationException("Please implement the AppointmentScheduler.isAfternoonAppointment() method"); |
| 23 | + return appointmentDate.getHour() >= 12 && appointmentDate.getHour() < 18; |
15 | 24 | } |
16 | 25 |
|
17 | 26 | public String getDescription(LocalDateTime appointmentDate) { |
18 | | - throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getDescription() method"); |
| 27 | + // throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getDescription() method"); |
| 28 | + DateTimeFormatter printer = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy, 'at' h:mm a'.'"); |
| 29 | + return "You have an appointment on "+printer.format(appointmentDate); |
19 | 30 | } |
20 | 31 |
|
21 | 32 | public LocalDate getAnniversaryDate() { |
22 | | - throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getAnniversaryDate() method"); |
| 33 | + // throw new UnsupportedOperationException("Please implement the AppointmentScheduler.getAnniversaryDate() method"); |
| 34 | + return LocalDate.of(LocalDate.now().getYear(), 9,15); |
23 | 35 | } |
24 | 36 | } |
0 commit comments