Ex3 - how to test it
konradin23
java
02/18/2026 10:40 AM
1.2 KB
27
Indexable
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
public class SubscriptionService {
private final BillingGateway billingGateway;
public SubscriptionService(BillingGateway billingGateway) {
this.billingGateway = billingGateway;
}
public void processSubscription(String userId) {
LocalDateTime now = LocalDateTime.ofInstant(
Instant.now(),
ZoneId.systemDefault()
);
boolean isWeekend = now.getDayOfWeek() == DayOfWeek.SATURDAY
|| now.getDayOfWeek() == DayOfWeek.SUNDAY;
if (isWeekend) {
billingGateway.applyWeekendDiscount(userId);
} else if (now.getHour() >= 22 || now.getHour() < 6) {
billingGateway.applyNightDiscount(userId);
} else {
billingGateway.applyStandardRate(userId);
}
}
}Editor is loading...
Leave a Comment