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;
}
}