-
Notifications
You must be signed in to change notification settings - Fork 73
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
[Tan Zheng Fu Justin] iP #62
base: master
Are you sure you want to change the base?
Changes from 25 commits
f42ae0a
bfc9993
fa62ed7
de3a29a
80562eb
8ef614e
4989098
70e53d2
eb8183a
7ce3414
32fa901
c0ddd93
e113278
039b06e
86ce064
279c23b
a56eecb
f33a405
567d027
a936dae
1f00542
3042ebf
0165792
0430f62
e7d092d
2cf8d6c
1ae1024
ca35d97
37cb07d
c75238d
5c80014
4c80cb8
4a5fc94
76b2560
2533ea0
2bacb7a
ed507b4
280e1a5
b336949
a5cdbc3
109c613
a8b00ed
eb3d17c
e9104a1
4e1bd77
2d96ff4
5edc8b6
725c05c
930d0c6
63f424b
9761edc
e50b44d
254352e
6451c9d
8c411ab
0069b3b
a28c87b
a629b3f
540585f
b5438f7
8ed8add
44c81f8
20bfe89
c8c0737
2cc378d
627e158
82331b2
f42d5c9
1c3c54f
bb5dfa9
43b53d6
0f0c99a
bea671f
b5b9c39
ebc22c1
83257dc
10826a5
92e89ce
84523ee
111afbb
8a03770
f34c442
e82c41f
5f76081
48a8034
2eb84ab
477c5d5
6743bcd
c56f850
adebdf5
02b0471
5ca80b4
4e1328c
98e313b
ee23323
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 |
---|---|---|
@@ -1,10 +1,96 @@ | ||
/** | ||
* CS2113T Semester 2 AY19/20 | ||
* Individual Project | ||
* | ||
* Project Duke is a educational software project designed to take you through | ||
* the steps of building a small software incrementally, | ||
* while applying as many Java and SE techniques as possible along the way. | ||
* | ||
* The project aims to build a product named Duke, a Personal Assistant Chatbot that | ||
* helps a person to keep track of various things. The name Duke was chosen as a placeholder name, | ||
* in honor of Duke, the Java Mascot. You may give it any other name and personality you wish. | ||
* | ||
* @file/s: Duke.java Printer.java Storage.java Task.java | ||
* @author: Tan Zheng Fu Justin | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
static Storage myTasks = new Storage(); | ||
|
||
public static void start() { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
Printer.printStart(logo); | ||
} | ||
|
||
public static void exits() { | ||
Printer.printLines(); | ||
Printer.printIndentation(); | ||
Printer.printBye(); | ||
Printer.printLines(); | ||
} | ||
|
||
public static Task readFromUser() { | ||
Scanner in = new Scanner(System.in); | ||
String userInput; | ||
|
||
userInput = in.nextLine(); | ||
Task task = new Task(userInput); | ||
|
||
return task; | ||
} | ||
|
||
public static String[] parseCommand(String description) { | ||
String[] commands = description.split(" "); | ||
return commands; | ||
} | ||
|
||
public static void echoUntilBye() { | ||
boolean isBye = false; | ||
while (!isBye) { | ||
Task task = readFromUser(); | ||
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. I think we can create a new Task only after we get the command which requires to do so.Since if the command is "list" or "bye", then there is no need to so. |
||
String[] commands = parseCommand(task.description); | ||
String command = commands[0]; | ||
switch (command) { | ||
case "bye": | ||
isBye = true; | ||
exits(); | ||
continue; | ||
case "list": | ||
myTasks.displayTasks(); | ||
continue; | ||
case "done": | ||
try { | ||
int index = Integer.parseInt(commands[1]); | ||
Task t = myTasks.getTask(index); | ||
if (Task.isValid(t)) { | ||
t.markAsDone(); | ||
Printer.printConfirmationMessage(t); | ||
} else { | ||
Printer.printError(); | ||
} | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
Printer.printError(); | ||
} | ||
continue; | ||
|
||
default: | ||
myTasks.storeTasks(task); | ||
Printer.printConfirmationMessage(task.description); | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
start(); | ||
Printer.printLines(); | ||
Printer.printGreetings(); | ||
Printer.printLines(); | ||
echoUntilBye(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import java.util.List; | ||
|
||
public class Printer { | ||
public static void printIndentation() { | ||
System.out.print(" "); | ||
} | ||
|
||
public static void printStart(String logo) { | ||
System.out.println("Hello from\n" + logo); | ||
} | ||
|
||
public static void printGreetings() { | ||
printIndentation(); | ||
System.out.println("Hello! I'm Duke"); | ||
printIndentation(); | ||
System.out.println("What can I do for you?"); | ||
} | ||
|
||
public static void printLines() { | ||
printIndentation(); | ||
System.out.println("---------------------------------------"); | ||
} | ||
|
||
public static void printBye() { | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
|
||
public static void printConfirmationMessage(String text) { | ||
printLines(); | ||
printIndentation(); | ||
System.out.println("Added: " + text); | ||
printLines(); | ||
} | ||
|
||
public static void printConfirmationMessage(Task task) { | ||
printLines(); | ||
printIndentation(); | ||
System.out.printf("Nice! I've marked this task as done:\n"); | ||
printIndentation(); | ||
System.out.printf(" [%s] %s\n", task.getStatusIcon(), task.getDescription()); | ||
printLines(); | ||
} | ||
|
||
public static void printTasks(List<Task> myList) { | ||
printLines(); | ||
if (myList.isEmpty()) { | ||
printIndentation(); | ||
System.out.println("List is empty."); | ||
} else { | ||
for (int i = 0; i < myList.size(); i++) { | ||
printIndentation(); | ||
Task temp = myList.get(i); | ||
String symbol = temp.getStatusIcon(); | ||
System.out.printf("%d.[%s] %s\n", i + 1, symbol, temp.getDescription()); | ||
} | ||
} | ||
printLines(); | ||
} | ||
|
||
public static void printError() { | ||
printLines(); | ||
printIndentation(); | ||
System.out.println("Error.. ;-;"); | ||
printLines(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Storage { | ||
private List<Task> myTasks = new ArrayList<>(); | ||
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. Is it enough to just import ArrayList class? Since I think you can directly define the type of myTasks as ArrayList. |
||
|
||
public void storeTasks(Task task) { | ||
myTasks.add(task); | ||
} | ||
|
||
public void displayTasks() { | ||
Printer.printTasks(myTasks); | ||
} | ||
|
||
public Task getTask(int index) { | ||
try { | ||
return myTasks.get(index - 1); | ||
} | ||
catch(Exception e) { | ||
return null; | ||
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 you can use Printer to give some error messages if any exception has been caught. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getDescription() { | ||
String description = this.description; | ||
return description; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "\u2713" : "\u2718"); | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
public static boolean isValid(Task task) { | ||
return task != null; | ||
} | ||
} |
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.
Do you agree that the description of a task is actually the part after the first word of the user input? ( If according to the user input, we need create a task)