Java代写:COMP2503 To Do List Program

实现一个To Do List的应用程序,熟悉Array和ArrayList的使用方法。

Objectives

  • Review of Java basics of java (Primative data types, objects, I/O)
    • Includes arrays and ArrayLists
  • Create classes and use objects

The Problem - To Do list program

Short Description

  • Creating an object oriented (also referred to as OO) program that helps a user build and manage a “to do” list.
  • At a very minimum you will need to create three classes
    • a starting point - the main and anything used for the basic flow of the program
    • ToDoEntry - holds information and functionality about a single to do list entry
      • Priority and description
    • ToDoList - all functionality related around managing a list of to do entries.
      • This class should not include any communication with the user other than reporting errors.
  • You cannot use the key word static anywhere in your program except for the main.

Long Description

In an object oriented design, important data structures are encapsulated in classes. The client code instantiates objects and then communicates with these objects via their public interfaces (“methods”). It has no access to their private implementations. At run time, an object oriented system is often viewed as an intercommunicating network of objects and client code.

When the program is run it reads a text file; to_do.txt. If the file is empty or the file name does not exist, the program starts with an empty “to do” list. Otherwise, it attempts to open the file and, if successful, creates a “to do” list of the items in the file.

Example, to_do.txt might look like:

1 finish COMP 2503 assignment 1
2 pay overdue MasterCard bill
2 do laundry
3 drink
2 buy groceries
1 make dentist appointment

The integer at the beginning of a line is the item’s priority (3 = high, 2 = medium and 1= low). If the integer value is not 1, 2 or 3, then it defaults to a value of 1 (low).

If any errors occur when reading information on a line (i.e., missing the priority integer or missing description) output an error message to the console and the entire line that was wrong and continue to the next line in the file.

When the program quits, it writes information to out.txt. If this file exists, then it is overwritten. Otherwise, a new file is created and all information is written out. The output format must match the input format (to_do.txt) for the program as shown above. The current list will be written out using the following format:

3 drink
2 pay overdue MasterCard bill
2 do laundry
2 buy groceries
1 finish COMP 2503 assignment 1
1 make dentist appointment

Once the initial “to do” list has been read, the program will read the commands from cmd.txt repeatedly until no more commands are left in the file. You can assume that there will be no errors in the cmd.txt file. The cmd.txt can contain four different commands: d (display), a (add), r (remove), and u (update). An example cmd.txt might look like:

d
a h phone Aunt to wish her happy birthday
r 2
u 4 h
d

Each of the four commands are explained below using the example from to_do.txt discussed above.

The “d” command, i.e. “display” will display the current list to the screen using the following format:

High Priority:
  1: - drink
Medium Priority:
  2: - pay overdue MasterCard bill
  3: - do laundry
  4: - buy groceries
Low Priority:
  5: - finish COMP 2503 assignment 1
  6: - make dentist appointment

Note that the list items are numbered. These numbers will play a part in the “remove” and “update” commands.

The “a” command (i.e., “add”) will be in the following format in the cmd.txt file:

a h phone Aunt to wish her happy birthday

In the above example, “a” is the command for add, followed by a single character for the priority (h / m / l) and then followed by the description. The new list item must be added at the end of the sub-list of the given priority. For example, if the display command was re-executed after the above “a” command is completed, it would display the following:

High Priority:
  1: - drink
  2: - phone Aunt to wish her happy birthday
Medium Priority:
  3: - pay overdue MasterCard bill
  4: - do laundry
  5: - buy groceries
Low Priority:
  6: - finish COMP 2503 assignment 1
  7: - make dentist appointment

Notice we have a second entry under high priority and the list numbers have been updated to accommodate this.

The “r”, “remove” command behaves as follows:

r 4
d

Here, “r” is remove, and 4 is the item number in the display list. In our most recent example, “do laundry” is the item to be removed. Now, “d” will display the list after removing item 4:

High Priority:
  1: - drink
  2: - phone Aunt to wish her happy birthday
Medium Priority:
  3: - pay overdue MasterCard bill
  4: - buy groceries
Low Priority:
  5: - finish COMP 2503 assignment 1
  6: - make dentist appointment

Notice the previous list item #4 “do laundry” is removed and the list numbers have once again been updated accordingly.

The “u” or the “update” command allows users to change the priority of a given item. For example, if the user suddenly realizes that the assignment is due soon, then the command read will be:

u 5 h
d

Here, “u” stands for update, 5 is the item number and “h” is the new priority. After the update, the list will be displayed as follows:

High Priority:
  1: - drink
  2: - phone Aunt to wish her happy birthday
  3: - finish COMP 2503 assignment 1
Medium Priority:
  4: - pay overdue MasterCard bill
  5: - buy groceries
Low Priority:
  6: - make dentist appointment

Notice that the entry “finish COMP 2503 assignment 1” is now listed at the end of the high priority section.

Once the command file has been read, the program will write the “to do” list to a text file called “out.txt”. Below is a sample of the output file for our example after the cmd.txt is executed:

3 drink
3 phone Aunt to wish her happy birthday
3 finish COMP 2503 assignment 1
2 pay overdue MasterCard bill
2 buy groceries
1 make dentist appointment

Documentation and Coding Style

Unused code or unessasry comments must be removed before you submit your assignment.

You must follow the documentation and codeing standards document found in the the assighnments section of blackboard. Failure to do so will result in the loss of marks.

Submission

Hand in a single file, last_first_a1.jar. The jar file should include all your .class files, .java files, and a class called A1 which has the main method. The date and time stamp on your submission will determine if the assignment is on time.

Incorrect submissions will result in the loss of marks (up to 5%).

After the due date, students will be permitted to submit up to 24 hours late at a 20% penalty and then up to 48 hours late at a 40% penalty.

Note: The cutoff times are sharp. Submissions made after 11:59 pm on the due date will receive a penalty. Submissions made after the penalty period has expired will receive a grade of zero. Therefore, students are strongly encouraged to submit incomplete assignments rather than nothing. Should you submit by the due date and then resubmit during the penalty period, your instructor will grade the version of your choice.

If you are submitting a late assignment you are required to email your instructor informing me of this fact. Failure to inform your instructor will result in a grade of zero.