Urgent Help Needed! Create a java class called Date212 to represent a date. It w
ID: 3567205 • Letter: U
Question
Urgent Help Needed!
Create a java 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. Two constructors should be provided,
one that takes three integer parameters, and one that takes a String (representing the date as in project
1). The constructor with the String parameter should validate the parameter as eight digit and not alphabet character and then
use the substring method of class String to pull out the month, day and year, parse them as integers
and call the three-argument constructor. The three-argument constructor should make sure that the
month and day values are legal. To call another constructor from within a constructor, use the method
this:
public Date212 (String d) { // the one-argument constructor
}
public Date212(int y, int m, int d){// 2nd constructor
......
}
List of Dates
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 linked list class called DateList. This should be a linked list with head node as described in
lecture. Modify it so that the data type in the nodes is Date212. The no-argument constructor should
create an empty list with first and last pointing to an empty head node, and length equal to zero.
Include two methods in class DateList: append and insert. The append method will add the new node to
the end of the list; the insert method will add the node in the proper position to keep the list sorted in
order by date.
Instantiate two linked lists, and for every date read from the file, add it to the first list using append, and
to the second list using 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. The Strings representing the dates may be compared using the compareTo method in class String. As you are reading the dates you should check that the value read in is legal (8 digits), and if it is not, print it to the console and do not put it in the array of dates.
ToString() for Class Date212.
Create a toString method in lass Date212 the 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 the following files to submit for this project:
Project2.java
Date212.java
DateGUI.java
DateNode.java
DateList.java
The input file
Each line of the input file may contain several dates separated by commas. You will need to use a
StringTokenizer to separate out the individual dates. So, an example of the input file would be:
.........................................................................................................
Output will be like:
in conole:
hello
200003
October
November
December
and in GUI display:
Create a java 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. Two constructors should be provided, one that takes three integer parameters, and one that takes a String (representing the date as in project 1). The constructor with the String parameter should validate the parameter as eight digit and not alphabet character and then use the substring method of class String to pull out the month, day and year, parse them as integers and call the three-argument constructor. The three-argument constructor should make sure that the month and day values are legal. To call another constructor from within a constructor, use the method this:Explanation / Answer
public class Project2 {
static DateList originalList=new DateList();
static DateList sortedList=new DateList();
public static void main(String[] args)
{
readDateFile();
//System.out.println("Original Dates");
originalList.printValues();
//System.out.println("Sorted Dates");
sortedList.printValues();
DateGUI.displayDate(originalList,sortedList);
}
public static void readDateFile()
{
File dateFile = new File("date.txt");
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]))
{
originalList.append(line[i]);
sortedList.insert(line[i]);
}
else
{
System.out.println(line[i]);
}
}
}
scan.close();
}
} catch (FileNotFoundException e) {
System.out.println("Error !!");
}
}
}
private static boolean isValidDate(String date) {
String regex = "\d+";
return date.matches(regex) && date.length()==8;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.