Skip to content

Commit c919dab

Browse files
committed
Solution for the Booking up for a Beauty Problem on Exercism.
Instructions: In this exercise you'll be working on an appointment scheduler for a beauty salon in New York that opened on September 15th in 2012.
1 parent 756235f commit c919dab

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
import java.time.LocalDate;
22
import java.time.LocalDateTime;
3+
import java.time.format.DateTimeFormatter;
34

45
class AppointmentScheduler {
56
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());
714
}
815

916
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());
1119
}
1220

1321
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;
1524
}
1625

1726
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);
1930
}
2031

2132
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);
2335
}
2436
}

0 commit comments

Comments
 (0)