Closed Th3C0d3Mast3r closed 2 days ago
@CYCLOP5 ensure this is checked in the frontend
Well, I was free and wrote its equivalent code in Java(and asked GPT to convert into JS, and here's the result) @CYCLOP5 , just check whether its right or no-and if, then you could go ahead with this
<!DOCTYPE html>
This is a code for Date Of Birth Checking.
import java.util.*; public class dobChecker { static Scanner obj=new Scanner(System.in); static String reply1=""; static String reply2, reply3, reply4; public static void main(String args[]) { run(); }
private static void run()
{
System.out.println("This is a code for Date Of Birth Checking.");
System.out.println("Press Any Key to proceed");
reply1=obj.nextLine();
if(reply1!=null || reply1!="")
{
checker();
}
else
{
System.out.println("ERROR!");
run();
}
}
private static void checker() {
System.out.print("\f");
int datess = 0, monthss = 0, yearss = 0; // initially, they are all set to zero
try {
System.out.print("Enter the DATE: ");
datess = obj.nextInt();
System.out.print("\nEnter the MONTH: ");
monthss = obj.nextInt();
System.out.print("\nEnter the YEAR: ");
yearss = obj.nextInt();
obj.nextLine(); // Consume the newline character
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter numeric values.");
obj.next(); // Clear the invalid input
checker();
return;
}
if (datess > 31 || datess < 1) {
System.out.println("Invalid Date-Retry");
checker();
return;
} else if (monthss > 12 || monthss < 1) {
System.out.println("Invalid Date-Retry");
checker();
return;
} else if (monthss == 2 && datess > (isLeapYear(yearss) ? 29 : 28)) {
System.out.println("Invalid Date-Retry");
checker();
return;
} else if ((monthss == 4 || monthss == 6 || monthss == 9 || monthss == 11) && datess > 30) {
System.out.println("Invalid Date-Retry");
checker();
return;
}
System.out.println("So, you entered the following DOB-is it correct?");
System.out.println(datess + "/" + monthss + "/" + yearss + " (DD/MM/YYYY)");
System.out.println("If no, then press \"N\" so as to re-enter");
String reply2 = obj.nextLine();
if (reply2.equalsIgnoreCase("N") || reply2.equalsIgnoreCase("nah") || reply2.equalsIgnoreCase("no")) {
checker();
} else {
nextFunction(datess, monthss, yearss);
}
}
private static boolean isLeapYear(int year) {
if (year % 4 != 0) {
return false;
} else if (year % 100 != 0) {
return true;
} else {
return year % 400 == 0;
}
}
private static void nextFunction(int day, int month, int year) {
// Placeholder for the next function to process the date
System.out.println("\fProcessing the date: " + day + "/" + month + "/" + year);
}
}
ISSUE WITH DOB
We need to ensure two things:-