Results 1 to 7 of 7

Thread: Need Help!!!!!!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    6

    Need Help!!!!!!!!

    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.




    please hlep me write the program, and after wirting the program, you can put the notes in the code so i can understand the whole thing.

    thanks in advance

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Need Help!!!!!!!!

    Yeah, sure. Can I give you a massage, too?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    6

    Re: Need Help!!!!!!!!

    Sure

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    6

    Re: Need Help!!!!!!!!

    ok here we go this is the one part of the program:

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


    Code:
    public class Project {
    	     
    	     public static void main(String[] args) {
    	         assert !isLeapYear(1900);
    	         assert isLeapYear(1984);
    	         assert !isLeapYear(1985);
    	         assert isLeapYear(2000);
    	     }
         
    	     /**
    	      * 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.
    	      */
    	     public static boolean isLeapYear(int year) {
    	         // this takes care of the first condition...
    	         if (year % 400 == 0) return true;
    	         
    	         // this takes care of the second condition...
    	         if ((year % 4 == 0) && (year % 100 != 0)) return true;
    	         
    	         // if neither of the conditions above are true, then we know our
    	         // year is not a leap year.
    	         return false;
    	     }
    	 
    	 }
    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 .


    please i have not much knowlege how to write this program pls help me finish this program, i really aperciate you helps thanks

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Need Help!!!!!!!!

    Well, that's a good start. Next, try the isValidDate method. A date is valid if:
    1) The month is between 1 and 12, inclusive.
    2) The day is between 1 and the number of days in the month. I recommend you write another method called "int daysInMonth(int month, int year)", which returns the number. Use isLeapYear to find out whether February has 28 or 29 days.
    The year is always valid, unless you want to forbid dates older than the Gregorian calendar itself.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    6

    Re: Need Help!!!!!!!!

    here's the next method, i need submit this program tomrr. pls help

    Code:
      public static int daysInMonth(int month, int year) {
         switch (month) {
         case 1: case 3: case 5: case 7: case 8: case 10: case 12:
           return 31;
         case 2: 
           if (isLeapYear(year)) 
    	 return 29;
           else
             return 28;
         default:
           return 30;
         }
      }
    
    
      public static boolean isValidDate(int month, int day, int year) {
        if ((month < 0) || (month > 12))
          return false;
        if (year == 0) 
          return false;
        if ((day < 0) || (day > daysInMonth(month,year)))
          return false;
        return true;
    }

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Need Help!!!!!!!!

    Nearly. The lower bound for month and year is 1, not 0. Other than that, it's correct. (Weird parameter order, though.)
    Except that it takes integer arguments. You need another function that takes a string, parses it, and then passes the individual parts to your current isValidDate.

    You'll need String.indexOf, String.substring and Integer.parseInt for that.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width