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

1.Create a class called Date212 to represent a date. It will store the year, mon

ID: 3568440 • Letter: 1

Question

1.Create a class called Date212 to represent a date. It will store the year, month and day as integers (not

as a String), so you will need three private instance variables. The constructor with the String parameter should validate (isValidString(String) method to check whether its eight digit or not character, if not valid throw exception with appropriate message as stated in SL 3) the parameter and then use the substring method of class String to pull out the month, day and year, parse them as integers and make sure that the month and day values are legal(use another isValidDate(int, int, int) method).

public Date212 (String d) { // the one-argument constructor

}

2. Create a class called DateNode which has fields for the data (a Date212) and next (DateNode)

instance variables. Include a one-argument constructor which takes a Date as a parameter.

public DateNode (Date212 d) { . . }

The instance variables should have protected access. There will not be any get and set methods for the

Explanation / Answer

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class DateMain {

public static void main(String[] args) {
  DateGUI g=new DateGUI();
  g.displayDate();
}
public static void readDateFile(File dateFile,DateList sortedList,DateList unsortedList)throws IllegalDate212Exception
{
  
  if (!dateFile.exists()) {
   System.out.println("File not found");
   return;
  } else {
   try {
    Scanner scan;
    if (dateFile.exists()) {
     scan = new Scanner(dateFile);
     while (scan.hasNextLine()) {
      
      String[] line=scan.nextLine().split(",");
      for(int i=0;i<line.length;i++)
      {
       if(isValidDate(line[i]))
       {
        unsortedList.append(line[i]);
        sortedList.insert(line[i]);
       }
       else
       {
         new IllegalDate212Exception(line[i]);
       }
      }
     }
     scan.close();
    }

   } catch (FileNotFoundException e) {
    System.out.println("Error !!");
   }
  }

}
private static boolean isValidDate(String date) {
  String regex = "\d+";
  boolean validDate = false;
  if(date.matches(regex) && date.length()==8)
  {
   int year=Integer.parseInt(date.substring(0, 4));
   int month=Integer.parseInt(date.substring(4, 6)) ;
   int day=Integer.parseInt(date.substring(6));
   if (year < 9999 && year > 0000) {
    if (month <= 12 && month >= 1) {
     if (day >= 1 && day <= 31) {
      validDate=true;
     }
    }
   }
  }
  return validDate;
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote