Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a basic HTML page with a textbox in which a user will enter their date of

ID: 3761459 • Letter: C

Question

Create a basic HTML page with a textbox in which a user will enter their date of birth, use an event (for example the input box keydown event, or a button's click event) to store the birthdateas a cookie. When the page is refreshed, get the cookie value and compare it to the current date. Print out a message that displays how many more days there are until the next birthday but only if the cookie has been set. Optional: If the cookie is set, hide the input box and display the birthdate in its place.

There are various methods for reading cookies, use the example from the book, find an example online, or write your own using loops or regular expressions to parse the value. I will not require you to worry about calculating leap years, so it is safe to make the assumption that a year is 365 days for this lab assignment. As long as you are within the ballpark of a few days or so, that will be acceptable.

Explanation / Answer

import java.time.LocalDate;

import java.time.Month;

import java.time.Period;

import java.time.temporal.ChronoUnit;

public class Main

{

    public static void main(String[] args)

{

        LocalDate today = LocalDate.now();

        LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

        LocalDate nextBDay = birthday.withYear(today.getYear());

        if (nextBDay.isBefore(today) || nextBDay.isEqual(today))

{

            nextBDay = nextBDay.plusYears(1);

        }

        Period p = Period.between(today, nextBDay);

        long p2 = ChronoUnit.DAYS.between(today, nextBDay);

        System.out.println("There are " + p.getMonths() + " months, and " +

                         

p.getDays() + " days until your next birthday. (" + p2 + " total)");

    }

}