Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.time.LocalDate; import java.time.Period; import java.util.Scanner; class AgeCalculator { public static void main ( String [ ] args ) { System.out.println ( Hello ,

import java.time.LocalDate;
import java.time.Period;
import java.util.Scanner;
class AgeCalculator {
public static void main(String[] args){
System.out.println("Hello, Welcome to the Age Calculator!");
LocalDate cd = LocalDate.now();
// cd= Current date
Scanner s = new Scanner(System.in);
System.out.println("Enter your birthdate: (year, month, day");
int y = s.nextInt();
int m = s.nextInt();
int d = s.nextInt();
LocalDate bd = LocalDate.of(y,m,d);
// bd= Birth date
Period agePeriod = Period.between(cd,bd);
int age = agePeriod.getYears();
// Retrieve the years from the agePeriod
System.out.println("Your age is "+ agePeriod); // Print the age
// control access
if (age >=18){// Check if the age is greater than or equal to 18
System.out.println("You Have Access");
} else {
System.out.println("You Do Not Have Access");
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Find all p > 0 such that the following series converges: klog(1) 1

Answered: 1 week ago