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: 3568172 • 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

two instance variables.

Create a class hierarchy which has an abstract class called DateList (The no-argument constructor should create an empty list with first and last pointing to an empty head node, and length equal to zero.). This class should have two subclasses: UnsortedDateList and SortedDateList, each having a method called add. In the UnsortedDateList, the method add will add to the end of the list (append), and in the SortedDateList it will do an insert(which will sort the data itself).

3. Create a new exception called IllegalDate212Exception by extending lllegalArgumentException.

4. When you create a new Date212 from a String read from the input file, catch any exceptions

thrown by the constructor and print the offending string to the console along with the message

from the Exception.

5. Add a File menu to your GUI which has menu items for Open and Quit. You should now be able

to select an input file using the GUI.

6. Instantiate two linked lists i.e. unsortedlist ans sortedlist, and for every date read from the file, add it to the first list using add (append), and to the second list using add (insert). You will end up with the first list having the dates from the input file in the order they were read, and in the second list the dates will be in sorted order. Display the unsorted and sorted dates in the GUI. In GUI use gridlayout to make it two column for unsorted and sorted datelist.

7. Create a toString method in lass Date212 that will return the date in the form mm/dd/yyyy. Use this

method to display the dates in the GUI.

Submitting the Project.

You should now have at least the following files to submit for this project:

Project3.java

Date212.java

DateGUI.java

DateNode.java

DateList.java

UnsortedDateList.java

SortedDateList.java

FileMenuHandler.java

input file:

20141001
20131103
19990205
20080304,20080305,20080306
19990206,hello,20141001,200003
20050505
October
November,December
19640503
19980703
19642199
20141013

output:

Before file choose and then after file choose.

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