I am having a problem completing this Java program. Basically everything is complete and running correctly except the end (which I cannot figure out the code for). The point of this program is to convert dates from the "Month Day, Year" format to "DD-Mon-YYYY" format and increment the dates by one year and one day. I have already coded it to incrementate the dates. What I need help with it figuring out how to implement the asDDMMMYYYY method in this program (which will change the date format). The program already knows that it needs to change to this new date format, but I just have to basically implement this method so it does this. I just need help with the code at the very end where it says code goes here. Any suggestions? I really need help!!

 import java.util.Scanner;  // for reading input data
   import java.io.*;                // for connecting to a data file

/** Java application that reads a sequence of date values from a file, and for each value
 ** determines the date one full year plus one additional day later (i.e. that would be 
 ** 366 or 367 days later) and then prints this revised date.  Essentially then, this 
 ** program reads in a value, modifies it in a specific way, and then prints the 
 ** resultant value.  
*/
   public class YearAndADayApplication {

      public static void main(String[] args) throws IOException {

      // Establish Scanner object to interpret input entered through a data file.
         Scanner input = new Scanner(new File(args[0]));
      // Loop to read each line of data from the data file and process it
         while(input.hasNextLine()) {
            // Read a complete line from the data file and ignore leading and trailing blanks
            String S = input.nextLine().trim();
            System.out.print(QUOTES + S + QUOTES + " becomes ");

            // Recognize the string input as the date value it represents
            SimpleDate sd = parseDate(S);
            //System.out.print(QUOTES + sd.toString() + QUOTES + BLANK);    //For debugging only

            // Modify the date by one full year and an additional day
                sd.nextDay();
                sd.setYear(sd.getYear() + 1);

            //System.out.print(QUOTES + sd.toString() + QUOTES + BLANK);    //For debugging only

            // Print the resultant value in the desired form
            System.out.println(QUOTES + asDDMMMYYYY(sd) + QUOTES);
         }
      }

    //String constants useful in the accomplishment of this task
      static final String MONTHS = "JanFebMarAprMayJunJulAugSepOctNovDec";
      static final String BLANK = " ";
      static final String COMMA = ",";
      static final String DASH  = "-";
        static final String QUOTES = "\"";

    /** Returns a SimpleData object that represents the date value expressed
    *  by the given string argument.  .
    *  @param original A string assumed to be a valid date in the form, Month day, year
    */      
      static SimpleDate parseDate(String original) {
         SimpleDate result = new SimpleDate();  //Construct an object
        String Month;
            Month = original.substring(0,3);
            int monthNumber = (MONTHS.indexOf(Month) / 3) + 1;
            result.setMonth(monthNumber);

            String Year;
           int lastBlank = original.lastIndexOf( ' ' );
            int yearBegin = lastBlank + 1;
            int yearEnd = original.length();
            Year = original.substring(yearBegin,yearEnd);
            int yearNumber = Integer.parseInt(Year);
            result.setYear(yearNumber);

            String Day;
            int firstBlank = original.indexOf( ' ' );
            int dayBegin = firstBlank + 1;
            int dayEnd = original.indexOf( ',' );
            Day = original.substring(dayBegin,dayEnd);
            int dayNumber = Integer.parseInt(Day);
            result.setDay(dayNumber);

         return result;
      }

    /** Returns a String that expresses the date value represented by the given object.
    *   The string expresses the date in the form DD-Mon-YYYY.
    *  @param date The given date value.
    */      
      static String asDDMMMYYYY(SimpleDate date) {
         String result = "";        //Declare an empty string as the initial result
            //<<code goes here>>
           return result;
      }

   }

Is this your problem: Given a SimpleDate object, how do you get the needed pieces of data from it to create the String you want?

Where is the SimpleDate class defined? Do you have API doc for it? What methods does it have that will return the values you want?

Yes, I believe that is the problem. The SimpleDate class is defined in my Java folder so it will run and the dates are already programed in through a Date.txt file. The asDDMMMYYYY method will return the results in the changed formate I need because it is already in the program. But, I just have to tell Java to implement that method. I believe it has something to do with toString method??

You need to read the API doc for the SimpleDate class (or read the source file) to see what methods it has that you can use to get the data you need in the asDDMMMYYYY() method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.