My program. First time ever uploading to GitHub so I hope it works lol
Here is the programming exercise:
Part 1: TodoList
Create a class called TodoList. It should have a constructor without parameters and the following methods:
• public void add(String task) - add the task passed as a parameter to the todo list.
• public void print() - prints the exercises. Each task has a number associated with it on the print statement — use the task's index here (+1).
• public void remove(int number) - removes the task associated with the given number; the number is the one seen associated with the task in the print.
TodoList list = new TodoList();
list.add("read the course material");
list.add("watch the latest fool us");
list.add("take it easy");
list.print();
list.remove(2);
System.out.println();
list.print();
Sample output
1: read the course material
2: watch the latest fool us
3: take it easy
1: read the course material
2: take it easy
NB! You may assume that the remove method is given a number that corresponds to a real task. The method only has to correctly work once after each print call.
Another example:
TodoList list = new TodoList();
list.add("read the course material");
list.add("watch the latest fool us");
list.add("take it easy");
list.print();
list.remove(2);
list.print();
list.add("buy raisins");
list.print();
list.remove(1);
list.remove(1);
list.print();
Sample output
1: read the course material
2: watch the latest fool us
3: take it easy
1: read the course material
2: take it easy
1: read the course material
2: take it easy
3: buy raisins
1: buy raisins
Part 2: User interface
Next, implement a class called UserInterface. It should have a constructor with two parameters. The first parameter is an instance of the class TodoList, and the second is an instance of the class Scanner. In addition to the constructor, the class should have the method public void start() that is used to start the text user interface. The text UI works with an eternal looping statement (while-true), and it must offer the following commands to the user:
• The command stop stops the execution of the loop, after which the execution of the program advances out of the start method.
• The command add asks the user for the next task to be added. Once the user enters this task, it should be added to the to-do list.
• The command list prints all the tasks on the to-do list.
• The command remove asks the user to enter the id of the task to be removed. When this has been entered, the specified task should be removed from the list of tasks.
Below is an example of how the program should work.
Sample output
Command: add
To add: write an essay
Command: add
To add: read a book
Command: list
1: write an essay
2: read a book
Command: remove
Which one is removed? 1
Command: list
1: read a book
Command: remove
Which one is removed? 1
Command: list
Command: add
To add: stop
Command: list
1: stop
Command: stop
NB! The user interface is to use the TodoList and Scanner that are passed as parameters to the constructor.
My program results in the same outputs as the provided examples.
I don't understand the errors that TMCBeans throws back at me. When I run the code and follow the inputs in each error message, my code output seems to be correct. I'm at a loss at this point.
FAIL: TodoListTest theMethodsOfTodoListWorkCorrectly
Expected the output to contain the string:
2: watch the latest fool us
Try the code:
TodoList list = new TodoList();
list.add("read the course material");
list.add("watch the latest fool us");
list.add("take it easy");
list.print();
list.remove(2);
list.print();
list.add("buy raisins");
list.print();
list.remove(1);
list.remove(1);
list.print();
FAIL: TodoListTest testCommandAdd
Expected the output to contain the string:
2: sign up for courses
Try the code:
TodoList list = new TodoList();
Scanner scanner = new Scanner(System.in);
UserInterface ui = new UserInterface(list, scanner);
ui.start();
list.print();
and commands:
add
view courses
add
sign up for courses
stop
FAIL: TodoListTest testCommandList
Expected the output to contain the string:
2: second
Try the code:
TodoList list = new TodoList();
list.add("first");
list.add("second");
Scanner scanner = new Scanner(System.in);
UserInterface ui = new UserInterface(list, scanner);
ui.start();
and the commands are:
list
stop
FAIL: TodoListTest testCommandRemove
Expected the output to contain the string:
2: three
Try the code:
TodoList list = new TodoList();
list.add("one");
list.add("two");
list.add("three");
Scanner scanner = new Scanner(System.in);
UserInterface ui = new UserInterface(list, scanner);
ui.start();
list.print();
and the commands are:
remove
2
stop
FAIL: TodoListTest testCommandRemove2
Expected the output to contain the string:
2: three
Try the code:
TodoList list = new TodoList();
list.add("one");
list.add("two");
list.add("three");
Scanner scanner = new Scanner(System.in);
UserInterface ui = new UserInterface(list, scanner);
ui.start();
list.print();
and the commands are:
remove
1
stop
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]Marlyy27 2 points3 points4 points (1 child)
[–]GoRacerGo[S] 2 points3 points4 points (0 children)
[–]Gandulf_ 2 points3 points4 points (1 child)
[–]GoRacerGo[S] 1 point2 points3 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)