CS 161 Homework 7 - To Do List
Due Thu Apr 04 at 11:59pm
Overview
ArrayLists are an ideal class for letting us organize and track information. In this assignment, you will use ArrayLists in writing a program to maintain a "To Do List"--a list of tasks that need to be done. This list will be managed through the command-line. Your list will support a number of functions including: adding new tasks, printing out all of the tasks, marking tasks as complete, removing tasks, and finding tasks that are due in the near future.
Below are a frew representative samples of what the output of your program should look like:
Select an option: 1. List all tasks in the to do list 2. Add a task to the to do list 3. Mark a task as completed 4. Remove a task from the to do list 5. Remove all completed tasks 6. List all tasks due due soon 7. Get the next task to do 8. Exit system > 1 *** YOUR TO DO LIST *** <<COMPLETED>> Write "to-do list" assignment <<INCOMPLETE>> Pay taxes due Mon Apr 15 13:00 2013 <<INCOMPLETE>> Feed the cat due Mon Apr 01 18:30 2013 <<COMPLETED>> Save the world from evil killer robots <<INCOMPLETE>> Finish homework due Thu Apr 04 23:59 2013 ... > 6 *** TASKS DUE WITHIN 3 DAY(S) *** <<INCOMPLETE>> Feed the cat due Mon Apr 01 18:30 2013 <<INCOMPLETE>> Finish homework due Thu Apr 04 23:59 2013 ... > 7 *** NEXT TASK TO DO *** <<INCOMPLETE>> Feed the cat due Mon Apr 01 18:30 2013
Note that I am providing the menus and interaction for you--all you need to do is actually add the to do list's functionality!
This assignment should be completed individually. You are welcome to ask for help (either from me or from your classmates), but remember the Gilligan's Island rule!
Objectives
- To practice working with ArrayLists
- To practice reading documentation and implementing a class based on it.
- To be able to design and create a program (mostly) on your own
- To practice breaking up code into helper methods
- To gain revenge upon the GregorianCalendar class by using a custom-made class for tracking time
- To review developing simple "model" classes
Necessary Files
You will need to download and extract the BlueJ project from the Homework7.zip file. This project includes two provided classes: This project will supply you with the following classes:
-
DateTime
This is a "wrapper" class (a class that offers a different set of methods) for the Java Calendar class. It will allow you to more easily represent and compare dates. Be sure to look at the documentation for the class (below and in BlueJ) to figure out how it works! -
ToDoListManager
This class will handle all the user interaction for managing your ToDoList. Be sure to take a moment and look over this class and get a feel for what it does--you will not need to modify it, but it's handy to look over other people's code to understand what they did!Note that this class has a main method so can serve as a "tester" class. You will likely want to also make your own Tester to make it easier to debug individual methods of your classes.
Finally, the project contains a README.txt file that you will need to fill out. Remember that you can open this file in BlueJ by double-clicking on the white paper icon!
Details
First, read through all of the assignment carefully. As you do so, think about what kinds of methods you might need, what kinds of variables you may want, and what kinds of functionality you will need.
Your program will need two classes: a Task
class to represent a Task, and a ToDoList
task that models your to do list. Both of these classes are required by the ToDoListManager. Note that most of your code will go inside the ToDoList class.
Again, you will probably want a ToDoListTester
class to help debug your program.
-
The first thing you should do is implement the
Task
class. This is a very basic class, similar to the classes we've created during lecture.- Your task class will need to have three attributes: a "description" (text explaining what the task is), a "due date" representing when the task is due (hint: use a DateTime object!), and whether or not the task has been completed. Think about what data types these attributes should be. Remember to make instance variables private!
- You will need at least one constructor, so that you can create a task with a specific description and due date. Note that tasks should default to being not completed (making a new Task that is already completed is a bit silly!)
-
You will also need some getters and setters for the instance variables--but not necessarily for all of them. You can either take some time to make all of them (so that they will be available if needed), or you can just add in the required ones as you find you need to get or set attributes of the Task!
- Style note! We usually name getters for boolean attributes "isSomething" rather than "getSomething". This makes the code highly readable (so I could ask whether a person "isHappy()" rather than whether a person "getHappy()")
-
The most complicated part of this class will be the
toString()
method. Not because toString methods are hard to write, but because you'll need to format the String representation of the Task so it matches the format demonstrated above.- If a task is completed, you should mark it as such and not display the due date. This will require a conditional statement.
- You can use String concatenation (like with the Hangman game's arrayToString method) to combine different Strings. Note that you can use
"\n"
(the "newline" character) to put a line break into a String.
- Be sure to test this class thoroughly--it will form the basis of the rest of your program!
-
The majority of your program's logic will be in the
ToDoList
class. Note that this class has some very specific structual requirements in order to work with ToDoListManager.- As the ToDoListManager won't compile without the ToDoList, you should start by making the "skeleton" of your class: basically empty methods and constructors. This is similar to what you did with the Photoshopper. Once you are finished, the ToDoListManager should compile and run, but won't do anything (at least until you finish adding functionality)!
- You can see a list of suggested (and required) method signatures in the documentation at the bottom of the page.
- As always, a good place to start is filling in any instance variables and the constructor(s). In particular, you'll probably need an instance variable that is an ArrayList of Tasks (an
ArrayList<Task>
)
-
A list of suggested (and required) method signatures can be found in the documentation at the bottom of the page. Read this documentation carefully to understand what each method should do! While I've included a few extra notes below, one of the goals of this assignment is for you to figure out how to structure each method on your own. But feel free to ask questions if you get stuck! Note that like the Hangman game, each method is pretty simple on its own. Don't overcomplicate things!
- Loops will continue to be your friend in this assignment. Remember we can use a foreach loop to easily run through an ArrayList, but we can also use for or while loops. The choice is yours.
-
Some of these functions require doing a "search" of the ArrayList. We can search a list by looking at each item in turn, seeing if that item matches our criteria (e.g., is the item we're looking for, is less than some threshold, etc), and if so doing something with that item (either returning it or adding it to another list of items to return).
- If we want to find the "biggest" (or smallest) item in a list, we can use what is called a "king of the hill" search. Basically we start off one person as the "king" (the biggest/smallest/bestest) item. We then go through everyone else, compare them to the king in a kind of challenge--if they are bigger/smaller/better than the king, then they become the new king, and the loop continues. Whoever is the king in the end must be the biggest/smallest/bestest item in the list!
-
The ArrayList class has a
removeAll()
method that takes in another ArrayList as a parameter, and then removes each item in that ArrayList from the current list. This is very handy for removing a large number of items: you can create an ArrayList of items to remove, and then call removeAll to remove them all at once! -
The DateTime object has a method
int compareTo(DateTime other)
that lets you compare two DateTimes to see which comes first chronologically.compareTo()
is a common function in Java.If I callobject1.compareTo(object2)
, the method will return a negative number (usually -1) if object1 comes "before" object2, 0 if the neither object comes first (so they are the same), or a positive number if object1 comes "after" object2. Thus:if(time1.compareTo(time2) < 0) { System.out.println(time1 + " is before " + time2); } else if(time1.compareTo(time2) > 0) { System.out.println(time1 + " is after " + time2); } else //time1.compareTo(time2) must be 0 { System.out.println(time1 + " and " + time2 + " are at the same time!"); }
- I recommend you start with the methods to add a Task to the ToDoList and to print out items in the list--this will make it easier to test the later methods.
- Be sure and text your code thoroughly--make sure that everything works before you turn in your assignment! Entering lots of new Tasks can get tedious, so you might use a separate Tester class to automatically create Tasks, add them to the list manually, and then call methods to see what happens. Or you can just enter bogus data into your program :)
- Each of your methods (including all of your helper methods) should have a full Javadoc comment (complete with @param and @return tags). Again, I suggest filling in these comments along with the skeleton (the method signatures of all your classes) when you first start--that way you will know what each method is supposed to do! Also include lots of inline comments that explain your code, both to help me and to help keep your place.
Timeline
This assignment is around the same size as Hangman, but you have a little less guidance so it may take longer. Get started early so that you have time to recover from any false starts (and there may be some false starts!)
- The
Task
class should be easy to write; try and get it done by Wed 03/27. - After that, try and get the skeleton of the ToDoList class implemented, along with the addTask and listTask methods by Fri 03/29.
- You can then write one or two of the remaining methods each day until the deadline.
- You should have plenty of time for this--and if you get it done early, you'll have more time to study for the exam!
Submitting
Check and double-check that your program works, that your code is commented, and that your name is in the class comment at the top of your program!
Be sure to complete the provided README.txt file with details about your program.
Upload the entire BlueJ project to the Hwk7 folder on the submission folder on hedwig. Make sure you upload your work to the correct folder!. This assignment is due at midnight on Thu Apr 04.
Extensions
There are lots of ways to extend this assignment and add more details to your To Do List (and the manager)
- Perhaps the most helpful would be to be able to save the to do list to a file, so you can reuse it between sessions! We'll talk about reading from a file; writing to a file isn't much more difficult (see Chapter 12 for details).
- Sorting the list of Tasks before printing them out might be a nice touch--that way I can see them in the order that they are due
- You can also add more details to a particular Task: for example, maybe Tasks have an "urgency" measure, or a "category" that we can use to organize them, or some other details. Think about what kinds of features you'd want in a task manager!
Grading
This assignment will be graded on approximately the following criteria:
- A fully implemented Task class (with an appropriate toString method) [10%]
- A ToDoList class that matches the requirements of the manager [5%]
- Ability to list the tasks [5%]
- Ability to add new tasks to the list [5%]
- Ability to mark a task as completed [10%]
- Ability to remove a task from the list [10%]
- Ability to remove all completed tasks [10%]
- Ability to list tasks that are due within a specified number of days [10%]
- Ability to get the "next" task to do [10%]
- Your code is carefully documented, with full Javadoc methods and inline comments [10%]
- Your code adheres to proper style guidelines. This means that variables are given descriptive names, tabs and braces are lined up, local variables aren't specified in the fields, etc. If you have any questions about good style, don't hesitate to ask! [10%]
- You have completed the included README.txt file [5%]
Documentation
Below is an example Javadoc from a working ToDoList.
Class ToDoList
java.lang.Object ToDoList
public class ToDoList extends java.lang.Object
A class that manages a list of tasks to do
Constructor Summary | |
---|---|
ToDoList()
Makes a new ToDoList object |
|
ToDoList(int todayYear,
int todayMonth,
int todayDayOfMonth)
Makes a new ToDoList object with the given year, month, and dayOfMonth representing "today" This constructor is optional. |
Method Summary | |
---|---|
void |
addTask(String description,
DateTime dueDate)
Adds a new Task to the to do list. |
Task |
getNextTask()
Returns the "next" task to do. |
void |
listAllTasks()
Prints out all of the tasks in the to do list |
void |
listNextTasks(int days)
Prints out all of the tasks in the to do list that are due within the specified number of days. |
void |
listTasks(ArrayList<Task> tasks)
A helper method that prints out the items in the given ArrayList of tasks. |
Task |
lookup(String description)
A helper method that finds the Task with the given description in the to do list |
boolean |
markTaskCompleted(String descr)
Marks the task with the given description as completed |
boolean |
remove(String description)
Removes the task with the given description from the to do list |
void |
removeCompleted()
Removes all completed tasks from the to do list |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
ToDoList
public ToDoList()
- Makes a new ToDoList object
ToDoList
public ToDoList(int todayYear, int todayMonth, int todayDayOfMonth)
- Makes a new ToDoList object with the given year, month, and dayOfMonth representing "today"
This constructor is optional.
- Parameters:
-
todayYear
- The year of "today"todayMonth
- The month of "today"todayDayOfMonth
- The day of the month of "today"
Method Detail |
---|
addTask
public void addTask(String description, DateTime dueDate)
- Adds a new Task to the to do list.
- Parameters:
-
description
- The description of the task to adddate
- The dueDate of the task to add
getNextTask
public Task getNextTask()
- Returns the "next" task to do. This is the incomplete task with the closest due date (that has not passed yet).
- Returns:
- The next task to do, or null if there is no task to do!
listAllTasks
public void listAllTasks()
- Prints out all of the tasks in the to do list
listNextTasks
public void listNextTasks(int days)
- Prints out all of the tasks in the to do list that are due within the specified number of days.
Note that this can include tasks that are completed or past due
- Parameters:
-
days
- How many days worth of tasks to list
listTasks
public void listTasks(ArrayList<Task> tasks)
- A helper method that prints out the items in the given ArrayList of tasks.
Note that this can be used to print either the tasks in the to do list, or another ArrayList of tasks
- Parameters:
-
tasks
- The ArrayList of tasks to print out
lookup
public Task lookup(String description)
- A helper method that finds the Task with the given description in the to do list
- Parameters:
-
description
- The description of the task to find - Returns:
- The task with the given description, or null if the task is not found
markTaskCompleted
public boolean markTaskCompleted(String descr)
- Marks the task with the given description as completed
- Parameters:
-
descr
- The description of the task to mark as completed - Returns:
- whether or not the task was marked completed (can be false if the task was not in the list)
remove
public boolean remove(String description)
- Removes the task with the given description from the to do list
- Parameters:
-
description
- The description of the task to remove - Returns:
- whether or not the task was removed (can be false if the task was not in the list)
removeCompleted
public void removeCompleted()
- Removes all completed tasks from the to do list