Calculate subscription expiration
Subscription services regularly need to calculate expiration dates for users. In this exercise, you'll create a custom method that calculates a user's subscription expiry date based on their subscription period.
This exercise is part of the course
Input/Output and Streams in Java
Exercise instructions
- Define method
calculateExpiration()
taking aLocalDate
and aninteger
for subscription length in days. - Calculate expiration date by adding the current date and days.
- Call the
calculateExpiration()
method with today's date and subscription of60
days.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import java.time.LocalDate;
public class Subscription {
// Create constructor with date and month
static LocalDate calculateExpiration(____ date, ____ days){
// Add days
return date.____(days);
}
public static void main(String[] args) {
LocalDate start = LocalDate.now();
// Call method to calculate the expiration date.
LocalDate expiration = calculateExpiration(____, 60);
System.out.println("Expiration date: " + expiration);
}
}