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

Think about it...how would YOU do it?

All you really have to do is additional testing in the year they would turn 18.
If they would turn 17 (or younger) this year they fail.
If they would turn 19 (or older) this year they pass (they're already 18).
If they turn 18 this year you have to compare the months.
If they turn 18 this month, you have to compare the date.

Write some more and ask again if you still can't figure it out, but post what you write along with a specific problem. Something like "It's doing X but I want it to do Y".

Think about it...how would YOU do it?

All you really have to do is additional testing in the year they would turn 18.
If they would turn 17 (or younger) this year they fail.
If they would turn 19 (or older) this year they pass (they're already 18).
If they turn 18 this year you have to compare the months.
If they turn 18 this month, you have to compare the date.

Write some more and ask again if you still can't figure it out, but post what you write along with a specific problem. Something like "It's doing X but I want it to do Y".

I see what you mean. Thank you Murtan. I can't wait to get out of the concepts class an into the real java class to get more help from the instructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.