1 Replies - 10984 Views - Last Post: 03 October 2006 - 11:27 PM Rate Topic: -----

#1 jimmy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 03-October 06

Parsing Input File and Date Validation

Post icon  Posted 03 October 2006 - 12:30 AM

first how's everyone doin, i am doing this program from two, three days, i changed my school this smester, i never took java before and this program is over my head, i have read some notes on sun.java.com..docu.... still not understood, at the bottom i wrote what i understood, pls help me i have to sumit this program by tomrr. ,

i am acutally more of the hardwar/software guy, if anybody need help with their computer regarding anything let me know, i will happy to assist you .


Program Description:
Given an input data file containing dates, one date per line, write a Java application Project.java which
will read lines of text from data file and put them into a partially-filled array of strings, and will then print
the contents of the array to a series of three JOptionPane message dialog boxes with text areas. The
first message box will display a column of the dates in the original order in which they were listed in the
file. The second message box will display a column of the dates sorted in lexicographical order, as
strings. The third message box will display a column of the dates in ascending order by date (earliest
date first).

Program should contain the following methods:

public static void main (String args[])
the main method for this program, it should call the
methods below as appropriate.

public static int readFile (String filename, String[] dates)
Reads from the file whose filename is given as a parameter, and fills array of strings
represending dates. Lines of the file that do not have proper date format (MM-DD-YYYY or
MM/DD/YYYY) or which represent invalid dates (such as 13/32/2006) should be rejected by
printing an error message to the console and not including them in the array. The test for validity
should be done by your isValidDate method below. The returned value is the number of dates
successfully put in the array.

public static void sortLines (String[] lines, int length)
Sorts the array of strings lexicographically using selection sort.

public static void sortDates (String[] dates, int length)
Sorts the array in date order using selection sort. In order to sort the date strings in order by
date, you will need to write an additional method called compareDate that will behave similarly
to compareTo method of the String class, except that it will sort by date rather than
lexicographically. To compare dates date, you will need to split the string into parts representing
the month, day, and year.

public static int compareDate(String date1, String date2)
compares two dates. Returns a negative number if date1 precedes date2, 0 if date1 is the
same as date2, or a positive number if date1 succeeds date2. This method is called from
within sortDate, which date strings by date.

public static void displayResults(String[] students, int length)
Prints the contents of the array to a JOptionPane.

public static boolean isValidDate(String date)
Returns true if and only if date has the proper format (MM-DD-YYYY or MM/DD/YYY) and has
appropriate values for the month (1 to 12) and day. Valid days may range from 1 to 31 in the
months of January, March, May, July, August, October, and December, and may range from 1
to 30 for the months of April, June, September, and November. In February, days may range
from 1 to 29 in a leap year, 1 to 28 in other years. Call your isLeapYear method, described
below, to determine whether a year is a leap year.

public static boolean isLeapYear(int year)
Returns true if and only if year is a leap year. A year is a leap year if it is a multiple of 400 or if
it is a multiple of 4 but not a multiple of 100.

--------------------------------------------------------------------
ok here's the one part of the program that i understood and wrote the code

 public static boolean isLeapYear(int year){
		 if((year%100 != 0) || (year%400 == 0)){
			 return true;
		 }
		 return false;
	}




----------------------------------------------------------------------
here's the second part that i understood and wrote

ublic boolean isValidDate(String date)
{
	 
   SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
   
   Date tDate = null;
   {
	 tDate = sdf.parse(date);
   }

   catch (ParseException e)
   {
	 errorMessage = "the date you provided is in an invalid date" +
							 " format.";
	 return false;
   }

   if (!sdf.format(tDate).equals(date)) 
   {
	 errorMessage = "The date that you provided is invalid.";
	 return false;
   }
   
   return true;

} // end isValidDate



This post has been edited by jimmy: 03 October 2006 - 09:19 AM


Is This A Good Question/Topic? 1
  • +

Replies To: Parsing Input File and Date Validation

#2 jimmy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 03-October 06

Re: Parsing Input File and Date Validation

Posted 03 October 2006 - 11:27 PM

help please
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1