-
Notifications
You must be signed in to change notification settings - Fork 114
[Low Beverly] iP #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[Low Beverly] iP #107
Changes from 14 commits
ab3b287
85bd6a5
afcf4e7
5c3cc13
9e97cef
eb4b65e
9fbf0c6
89920cc
b31dc7b
dced9db
7014334
2076ea4
258892c
50d89a6
f67a83f
1e1bb0c
0085d8f
01ea11f
9893111
0573acf
2361592
f5fcf14
1996a83
166d83b
9f1bc2c
0e6bae6
56d0e22
3b75765
b63bd20
79a8871
3d1361d
1527ab8
d8923aa
91f00e2
e7f6588
2a63fdc
6c8dfc5
3be8c65
adabff1
7ce6169
562d87d
1289341
cdf3bfb
3a40699
74dd30e
5de4602
9d6381c
769a80b
86639ed
95f37b6
c383183
e2cc91e
8dc1a20
2fa2497
b32e1fe
4b1bc2e
c9478f8
0f6e5f1
56dd508
2b98a0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class ChattyCharlie { | ||
|
|
||
| //TASK CLASS | ||
| public static class Task{ | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| //constructor | ||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| //check if its marked as done | ||
| public String getMarkedStatus() { | ||
| return (isDone ? "X" : " "); | ||
| } | ||
|
|
||
| //to toggle the task | ||
| public void markTask() { | ||
| this.isDone = true; //change the variable | ||
| } | ||
|
|
||
| public void unmarkTask() { | ||
| this.isDone = false; //change the variable | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //LIST CLASS | ||
| public static class List { | ||
| //make a list of task | ||
| private Task[] list; | ||
| private int size; | ||
|
|
||
| //constructor | ||
| public List() { | ||
| list = new Task[100]; | ||
| size = 0; | ||
| } | ||
|
|
||
| //Method to add an item to the list | ||
| public void addTask(String text) { | ||
| //create an instance for Task | ||
| Task newTask = new Task(text); | ||
| //add the text into the list | ||
| list[size] = newTask; | ||
| //account for the item | ||
| size++; | ||
| } | ||
|
|
||
| //To mark | ||
| public void mark(int index) { | ||
| if (index >= 0 && index < size) { | ||
| list[index].markTask(); | ||
| int remainingTask = countUnmarkedTasks(); | ||
| System.out.println(" Well Done! 1 task down, " + remainingTask + " to go."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the space identation could be made into a constant variable given its usage throughout the code. |
||
| System.out.println(" [" + list[index].getMarkedStatus() + "] " + list[index].description); | ||
| } else { | ||
| System.out.println(" Invalid task number."); | ||
| } | ||
| } | ||
|
|
||
| //To unmark | ||
| public void unmark(int index) { | ||
| if (index >= 0 && index < size) { | ||
| list[index].unmarkTask(); | ||
| int remainingTask = countUnmarkedTasks(); | ||
| System.out.println(" Hmmm, not quite done yet, " + remainingTask + " to go."); | ||
| System.out.println(" [" + list[index].getMarkedStatus() + "] " + list[index].description); | ||
| } else { | ||
| System.out.println(" Invalid task number."); | ||
| } | ||
| } | ||
|
|
||
| //To print list | ||
| public void toPrintList() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the function name could be clearer without using "to"? |
||
| //print all | ||
| int remainingTask = countUnmarkedTasks(); | ||
| System.out.println("ToDo List:"); | ||
| System.out.println("pending Task: " + remainingTask); | ||
| for (int i = 0; i < size; i++) { | ||
| int number = i+1; | ||
| System.out.println(" " + number + ".[" +list[i].getMarkedStatus() + "] " + list[i].description); | ||
| } | ||
| } | ||
|
|
||
| // Method to count how many tasks are unmarked | ||
| public int countUnmarkedTasks() { | ||
| int count = 0; | ||
| for (int i = 0; i < size; i++) { | ||
| if (!list[i].isDone) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
| } | ||
|
|
||
| //MAIN ALGO | ||
| public static void toDoMaker() { //Echo as a function | ||
| String line; | ||
| String you = "User: "; | ||
|
|
||
| //make the scanner | ||
| Scanner in = new Scanner(System.in); | ||
|
|
||
| //create an instance of list class | ||
| List toDo = new List(); | ||
|
|
||
| //accept an insert | ||
| while (true) { | ||
| System.out.print(you); | ||
| line = in.nextLine(); | ||
|
|
||
| //if the line contains bye, it signals the end | ||
| if (line.contains("Bye") || line.contains("bye")) { | ||
| break; | ||
| } | ||
| //add or print | ||
| if (line.equals("list")) { | ||
| toDo.toPrintList(); | ||
| } else if (line.startsWith("mark ")) { | ||
| //trim to get the task name | ||
| String taskDescription = line.substring(5).trim(); | ||
| boolean found = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the boolean variable could be named "isFound" for greater clarity? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Boolean is not in form of a question |
||
|
|
||
| //loop to find | ||
| for(int index = 0; index < toDo.size; index++) | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not following loop layout coding standard
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I dont understand what you mean, is this not the standard? There are curly brackets, can I clarfiy what fo you mean |
||
| if(toDo.list[index].description.equals(taskDescription)) { | ||
| toDo.mark(index); | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| if(!found) { | ||
| System.out.println(" Invalid task description"); | ||
| } | ||
| } else if (line.startsWith("unmark ")) { | ||
| String taskDescription = line.substring(7).trim(); | ||
| boolean found = false; | ||
|
|
||
| //loop to find | ||
| for(int index = 0; index < toDo.size; index++) | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, not following the loop layout coding standard |
||
| if(toDo.list[index].description.equals(taskDescription)) { | ||
| toDo.unmark(index); | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| if(!found) { | ||
| System.out.println(" Invalid task description."); | ||
| } | ||
| } else { | ||
| //add the item | ||
| toDo.addTask(line); | ||
| System.out.println(" Added: " + line); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| String logo = " _____ \n" | ||
| + " / \\ \n" | ||
| + " | O O | \n" | ||
| + " | \\___/ | \n" | ||
| + " \\_____/ \n" | ||
| + " /\\_____/\\ \n" | ||
| + " | | \n" | ||
| + " | | \n" | ||
| + " |_______| \n" | ||
| + " \n"; | ||
| String charlie = "Charlie: "; | ||
|
|
||
| String greeting = "Hello! I'm ChattyCharlie, your consistent buddy.\n" | ||
| + " What shall we do today?\n" ; | ||
|
|
||
| String farewell = "All the best in clearing your list!"; | ||
|
|
||
| System.out.println(logo + charlie+ greeting); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the spacing be consistent? |
||
| toDoMaker(); | ||
| System.out.println(charlie + farewell); | ||
|
|
||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could name the array something in plural, like tasks