Here are my instructions:
This assignment is already past due and my professor said he would comment on it to help me understand but I think he is too busy & it's irking my soul that I can't get it right so.... here i am... Any help would be wonderful.
ToDo List
- You will be handing in 2 classes. ToDoItem.java (defines the data type of a To Do Item) and MyList.java (the driver that allows the user to enter data, create ToDoItems, and manage ToDoItems).
- Design a class for a ToDoItem. A ToDoItem keeps track of an item you need to do (as a string), the date it is due (hmmm, what is a good way to do this?), the priority of that item (1 is high, 2 is medium, 3 is low), and if that item is or is not completed.
- Sketch-out a rough UML diagram of what this class would look like and what methods you would need for this class. You must include this with your assignment. You may use a CASE tool like ArgoUML or you can simply hand draw the diagram and submit a picture with your assignment.
- You must provide a constructor that accepts arguments for this class to set the object's default state.
- Write an overloaded method so that a user can set priority by int (1, 2, 3) or String ("high", "medium", "low").
- Then, write a simple menu-driven program that allows a user to create ToDo Items, delete them, view them all unsorted, and mark them as completed. Please see the attached file MyList.java for a small framework to help make your menu system more organized.
ToDo Notes & Hints
The attached file MyList.java is a basic framework for a simple command-line driven ToDo list. Use this as the basis for your ToDo assignment. There is a lot missing from this starter file but it will help you get up and running quicker.
import java.util.ArrayList;
import java.util.Scanner;
public class MyList {
public static ArrayList todoItems = new ArrayList();
public static void main(String[] args) {
while(true) {
printMenu();
processInput();
}
}
public static void printMenu() {
System.out.println("[a]dd an item");
System.out.println("[p]rint all");
System.out.println("[q]uit");
}
public static void processInput() {
Scanner s = new Scanner(System.in);
String input = s.next();
if(input.equals("a")) {
//addToDoItem();
}
else if(input.equals("p")) {
//printAll();
}
else if(input.equals("q")) {
System.exit(0);
}
}
// implement rest of processInput methods here
}
- Each feature such as create, view, delete, and mark read should be defined as a method so that your code can be easily read.
- Your ToDoItem class should have NO code related to user interface in it. Keep your user interface code separate from your data (this advice is based on a pattern called Model-View-Controller or MVC). This means your ToDoItem class might be pretty basic and that your "driver" file with your main method is doing most of the work.
- Use an Array or ArrayList to store your ToDoItems. Reference individual ToDoItems by their index in that data structure (print the index of each item when printing all ToDoItems).
- Once a ToDoItem is created it can NOT be edited beyond being marked as completed. If the user mistypes a date or incorrectly spells the title that item can only be deleted and then recreated to be fixed. This is to simplify the assignment. Again, marking an item as complete/incomplete is the only aspect of a ToDoItem that can be edited. Objects that cannot be edited are called immutable.
ToDo Program Thoughts
Here are some things to think about that we will address in a few weeks in this course. I included these items now so you can start to think about them.
What if we wanted to sort our items by date due or by priority or by both? - -Don't write this, just think about how we might do this.
What makes one ToDo -item less than, equal to, or greater than another?
We are writing a lot of code to manage our array of ToDoItems. What, if anyways, might we simplify this?
I have a video of a demo of the program: https://youtu.be/9eWkn7uOLs0
Here are the codes I have written so far. I am stuck and having trouble parsing my date and getting it to print out.
MyList.java
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
import java.text.*;
public class MyList {
public static ArrayList<ToDoItem> toDoItems = new ArrayList<>();
public static Scanner k = new Scanner(System.in);
private static String description;
private static String dueDate;
public static void main(String[] args) throws ParseException {
while(true) {
printMenu();
processInput();
}
}
public static void printMenu() {
System.out.println("[a]dd an item");
System.out.println("[d]elete an item");
System.out.println("[t]oggle complete");
System.out.println("[p]rint all");
System.out.println("[q]uit");
}
public static void processInput() throws ParseException{
Scanner s = new Scanner(System.in);
String input = s.next();
if(input.equals("a")) {
addToDoItem();
}
else if(input.equals("d")) {
//deleteToDoItem();
}
else if(input.equals("t")) {
// toggleComplete();
}
else if(input.equals("p")) {
printAll();
}
else if(input.equals("q")) {
System.exit(0);
}
}
public static ToDoItem addToDoItem() throws ParseException {
ToDoItem newItem;
newItem = null;
System.out.print("Enter an item to add to list: ");
String desc = k.nextLine();
if(desc.trim().length()==0) return newItem;
System.out.print("Enter Date (MM/dd/YYYY): ");
String dueDate = k.nextLine();
System.out.print("Enter priority between 1 and 3 (3 being the highest): ");
String prior = k.nextLine();
int p = Integer.parseInt(prior);
if(dueDate.trim().length()==0){
newItem = new ToDoItem(desc);
}
else {
newItem = new ToDoItem(desc, dueDate);
}
newItem.setPriority(p);
return newItem;
//toDoItems.add(new ToDoItem(desc, p, dueDate));
}
public static void printAll() throws ParseException {
ToDoItem item = new ToDoItem();
System.out.println(item);
//ToDoItem task = newItem.get(i);
// ***************
// You should not need to create ToDoItems here
// This method should loop through your array and print out each item
// Since you have a toString() method you can print the objects by passing
// them into like so inside of a loop System.out.println( item.get(i) )
//for(int i = 0; i < newItem.size(); i++) {
// System.out.println(toDoItems.get(i));
// }
// for(ToDoItem myItem : toDoItems) {
//ToDoItem myItem = toDoItems.get(i);
//System.out.println(myItem);
// System.out.println(myItem.getDescription()+" -"+myItem.getPriority()+"- ("+myItem.getDueDate()+")");
}
}
//public static void deleteToDoItem() {
// **********
// You won't need a loop here, you can directly
// delete the item at the given index.
// Prompt for an int, read in the int, then call item.remove(i);
//System.out.print("Enter index of item to delete: ");
//int delete = k.nextInt();
//toDoItems.remove(i);
// }
// public static void toggleComplete() {
/////
// }
//}
ToDoItem.java
import java.text.*;
import java.util.Date;
//import java.lang.NullPointerException;
public class ToDoItem {
private String description;
private Date dueDate;
private int priority;
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
public ToDoItem() {
}
public ToDoItem(String desc) {
description = desc;
dueDate = null;
priority = 0;
}
public ToDoItem(String desccription, String dDate) throws ParseException {
this.description = description;
dueDate = df.parse(dDate.trim());
}
public String toString() {
if(dueDate != null) {
return( description + " -"+priority+"- " + "Date not Set");
}
else {
return( description + " -"+priority+"- " + df.format(dueDate));
}
}
public void setPriority( int prio) {
if(prio<0) this.priority = 0;
else if(prio > 3) this.priority = 3;
else this.priority = prio;
}
public int getPriority() {
return this.priority;
}
public void setDueDate(String date) throws ParseException {
Date d = df.parse(date.trim());
this.dueDate = d;
}
public String getDescription() {
return description;
}
public String getDueDate() {
if(dueDate == null) return "";
return df.format(dueDate);
}
}