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

Write a java progrram with a given input file of dates represented as Strings, r

ID: 3564974 • Letter: W

Question

Write a java progrram with a given 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 20141001 for October 1, 2014). 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 thecompareTomethod 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.


About 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.

Submitting the Project.
You should have two files to submit for this project:
Project1.java
DateGUI.java

The input is follows:

Project1.txt

The answercannot use vector or anything advanced, also must have two classes that make up the java project and a textinputfile coding.Please make code as simple as possible.

Explanation / Answer

package sortnew;

import java.util.ArrayList;
import java.util.StringTokenizer;

public class DateSort {
public DateSort() {}

void dateSort() {
ArrayList dateData = new ArrayList();
String months[] = {"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};

dateData.add(0,"29-AUG-2008");
dateData.add(1,"13-FEB-2007");
dateData.add(2,"29-JAN-2008");

System.out.print(" Sorted Dates = ");

for(int i=0;i<dateData.size();i++){
for(int j=0;j<(dateData.size()-1-i);j++){

StringTokenizer date1=new StringTokenizer((String)dateData.get(j),"-");
StringTokenizer date2=new StringTokenizer((String)dateData.get(j+1),"-");
String date01[] = new String[3];
String date02[] = new String[3];
int k=0;
ArrayList temp=new ArrayList();

while (date1.hasMoreTokens()) {
date01[k]=date1.nextToken();
date02[k]=date2.nextToken();
k++;
}//saving DD-MMM-YYYY in 2 arrays

//------------------------Validate Year---------------------------
if(Integer.parseInt(date02[2]) < Integer.parseInt(date01[2])){
int t=0;
temp.add(t,dateData.get(j));
dateData.add(j,dateData.get(j+1));
dateData.add(j+1,temp.get(t));
temp.remove(t);
}

}
}
System.out.println(dateData.size());
for(int i=0;i<dateData.size();i++)
System.out.println(dateData.get(i));

// int tmp=0;
// int a[] = {6,4,3,5,2,1};
// for (int i=0; i<a.length; i++) {
// for (int j=0; j<a.length-1-i; j++)
// if (a[j+1] < a[j]) { /* compare the two neighbors */
// tmp = a[j]; /* swap a[j] and a[j+1] */
// a[j] = a[j+1];
// a[j+1] = tmp;
// }
// }
// for(int i=0;i<a.length;i++)
// System.out.println(a[i] + " ");

}

public static void main(String args[]) {
DateSort Dates = new DateSort();

Dates.dateSort();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote