import java.util.Calendar;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int userBirthDay = 0;
int userBirthMonth =0;
int userBirthYear=0;
Scanner input = new Scanner(System.in);
System.out.println("Enter The day of your birth");
userBirthDay = input.nextInt();
System.out.println("Enter The month of your birth");
userBirthMonth = input.nextInt();
System.out.println("Enter The year of your birth");
userBirthYear = input.nextInt();
Calendar calendar = Calendar.getInstance();
int today = calendar.get(Calendar.DAY_OF_MONTH);
int todayMonth= calendar.get(Calendar.MONTH)+1;
int todayYear = calendar.get(Calendar.YEAR);
if (Calendar.YEAR-userBirthYear > 17)
{
System.out.println("Purchase is denied");
}
else
{
System.out.println("Please continue to checkout");
}
}
}
Ok so this is a homework assignment and if I can't figure out the subtraction of the birth date from the current date I won't get full credit. The calculation should determine if the user is 18 or older and I can get it as far as just using the year but how do I get it to factor in the month and day? I'm happy with a point in the right direction!
Thanks in advance,
Bonnie