Advertisement
Flameancer

Task.java

May 29th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. /**
  2.  * This is the Task Class
  3.  * @author Jonathan Harris
  4.  * May 28, 2015
  5.  */
  6. import java.util.Date;
  7. import java.text.DateFormat;
  8. import java.text.SimpleDateFormat;
  9. import java.text.ParseException;
  10.  
  11.  
  12.  
  13. public class Task {
  14.  
  15.   public Date date;
  16.   public String description;
  17.  
  18.   /**
  19.   * Creates a new task with the given dueDate and description.
  20.   * dueDate must be in the format mm-dd-yyyy (e.g., 07-01-2014 for 1 July 2014); it's
  21.   * okay if this method crashes if the date format is incorrect.
  22.   */
  23.   public Task(String dueDate, String description) {
  24.     DateFormat format = new SimpleDateFormat("MM-dd-yyyy");
  25.     try {
  26.       date = format.parse(dueDate);
  27.     } catch (ParseException e) {
  28.       System.err.println("Invalid Date");
  29.     }
  30.     this.description = description;
  31.   }
  32.  
  33.   /**
  34.   * Gets the description of this task.
  35.   */
  36.   public String getDescription() {
  37.     return description;
  38.   }
  39.  
  40.   /**
  41.   * Gets the due date for this task.
  42.   */
  43.   public Date getDueDate() {
  44.     return date;
  45.   }
  46.  
  47.   public static void main(String[] args) {
  48.     Task testTask = new Task("05-23-15", "Making test task");
  49.     System.out.println("The task " + testTask.getDescription() + " was made on " +
  50.     testTask.getDueDate());
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement