package edu.pdx.cs410J.erik;

import edu.pdx.cs410J.AbstractAppointmentBook;
import sun.util.resources.cldr.ar.CalendarData_ar_YE;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * The main class for the CS410J appointment book Project
 */
public class Project1 {
  public static final String README = "By: Erik Paulson\n" +
          "CS410J Project 1: Designing an Appointment Book Application \n" +
          "A simple command line program that creates an AppointmentBook and Appointment with the given command line arguments.";
  public static final String DATE_WRONG_ERROR = "Date is not in 24-hour format: mm/dd/yyyy hh:mm";


  public static void main(String[] args) {
    Class c = AbstractAppointmentBook.class;  // Refer to one of Dave's classes so that we can be sure it is on the classpath
    boolean printDescription = false;

    if (args.length == 0) {
      System.err.println("Missing command line arguments");
      System.exit(1);
    }

    ArrayList<String> argList = new ArrayList<>(Arrays.asList(args));
    if (argList.contains("-readme")) {
      System.out.println(README);
      System.exit(0);
    }
    if (argList.contains("-print")) {
      printDescription = true;
      argList.remove("-print");
    }
    if (argList.size() != 4) {
      System.err.println("Incorrect command line arguments");
      System.exit(1);
    }
    String owner = argList.get(0);
    String description = argList.get(1);
    String start = argList.get(2);
    String end = argList.get(3);
    if (description.equals("")) {
      System.err.println("Description cannot be empty");
      System.exit(1);
    }

    if (!isDateValid(start) || !isDateValid(end)) {
      System.err.println(DATE_WRONG_ERROR);
      System.exit(1);
    }

    AppointmentBook book = new AppointmentBook(owner);
    Appointment appointment = new Appointment(description, start, end);
    book.addAppointment(appointment);

    if (printDescription) {
      System.out.println(appointment.toString());
    }

    System.exit(1);
  }

  private static boolean isDateValid(String date) {
    // mm/dd/yyyy hh:mm
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    ParsePosition position = new ParsePosition(0);
    simpleDateFormat.parse(date, position);
    if (position.getIndex() == 0) {
      return false;
    }

    return true;
  }

}
@@ -73,62 +73,8 @@
 ook;
-%0Aimport sun.util.resources.cldr.ar.CalendarData_ar_YE;
 %0A%0Aim
@@ -194,31 +194,8 @@
 ays;
-%0Aimport java.util.List;
 %0A%0A/*
@@ -550,16 +550,17 @@
 ents.%22;%0A
+%0A
   public
@@ -973,24 +973,94 @@
 (1);%0A    %7D%0A%0A
+    // Convert the array to an ArrayList to work with the data easier%0A
     ArrayLis
@@ -1116,16 +1116,83 @@
 (args));
+%0A%0A    // If -readme is passed, only print the README and do no more
 %0A    if 
@@ -1276,32 +1276,118 @@
 m.exit(0);%0A    %7D
+%0A%0A    // If the print option is passed, save that info for later and remove that param
 %0A    if (argList
@@ -1473,24 +1473,60 @@
 int%22);%0A    %7D
+%0A%0A    // Validate the number of args
 %0A    if (arg
@@ -1779,16 +1779,17 @@
 get(3);%0A
+%0A
     if (
@@ -2021,24 +2021,113 @@
 (1);%0A    %7D%0A%0A
+    // Create an AppointmentBook and Appointment based off of the command line arguments%0A
     Appointm
@@ -2385,17 +2385,17 @@
 xit(
-1
+0
 );%0A  %7D%0A%0A
   pr
@@ -2390,16 +2390,256 @@
 );%0A  %7D%0A%0A
+  /**%0A   * A helper function to validate the date passed in from the command line.%0A   * A valid date is of the form MM/dd/yyyy HH:mm%0A   *%0A   * @param date The date to validate%0A   * @return true if the date is valid, false otherwise%0A     */%0A
   privat

Add some comments