Sorting an Array of Dates Displaying in a GUI Given an input

Sorting an Array of Dates/ Displaying in a GUI

Given an input file of dates represented as Strings, read the dates from the file and display them in a

GUI. The dates will be in the form yyyymmdd (such as 20161001 for October 1, 2016). The GUI should

have a GridLayout with one row and two columns. The left column should display the dates in the order

read from the file, and the right column should display the dates in sorted order (using Selection Sort).

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.

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:

20161001

20080912,20131120,19980927

20020202,hello

20120104

Submitting the Project.

You should have two files to submit for this project:

Project1.java

DateGUI.java

Please give a java code

Solution

project1.java:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class FileReaderExample
{
public static void main(String[] args)
{
File file = new File(\"text.txt\");
try
{
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
int lineNo = 1;
while ((line = br.readLine()) != null)
{
// ignore the first line of Date Opening Closing
if (lineNo != 1)
{
String[] itemsOnLine = line.trim().split(\"\\\\s+\");
System.out.println(\"Your date is : \" + itemsOnLine[0]);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyymmd\");
java.util.Date yourDate = simpleDateFormat.parse(itemsOnLine[4]);
System.out.println(yourDate);

}
lineNo++;
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (ParseException e)
{
e.printStackTrace();
}
}
}

Sorting an Array of Dates/ Displaying in a GUI Given an input file of dates represented as Strings, read the dates from the file and display them in a GUI. The
Sorting an Array of Dates/ Displaying in a GUI Given an input file of dates represented as Strings, read the dates from the file and display them in a GUI. The

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site