Skip to content
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

Open
wants to merge 95 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
f42ae0a
Added greeting and exit methods
JustinnT Jan 21, 2020
bfc9993
Add echoUntilBye class for Level-1
JustinnT Jan 28, 2020
fa62ed7
Add list to store userInput
JustinnT Jan 28, 2020
de3a29a
Add introduction comments
JustinnT Jan 31, 2020
80562eb
Refractor print methods into new Printer class
JustinnT Jan 31, 2020
8ef614e
combine printer methods
JustinnT Jan 31, 2020
4989098
Added method to print tasks
JustinnT Jan 31, 2020
70e53d2
add feature to store and print userinputs into/from a string
JustinnT Jan 31, 2020
eb8183a
Fix infinite loop bug in method echoUntilBye
JustinnT Jan 31, 2020
7ce3414
implement new class to store userinput as tasks
JustinnT Jan 31, 2020
32fa901
Change parameter types due change of userinput type
JustinnT Jan 31, 2020
c0ddd93
change parameter type due to userinput type
JustinnT Jan 31, 2020
e113278
implemente printing symbols
JustinnT Jan 31, 2020
039b06e
changed userInput to store in new class type Task
JustinnT Jan 31, 2020
86ce064
Add new printing message on printing empty list
JustinnT Jan 31, 2020
279c23b
add print error method
JustinnT Jan 31, 2020
a56eecb
add method to mark task as done
JustinnT Jan 31, 2020
f33a405
add method to check if task is valid for exception handling
JustinnT Jan 31, 2020
567d027
renamed method to better reflect its function
JustinnT Jan 31, 2020
a936dae
add try catch statement to catch outofbounds exception
JustinnT Jan 31, 2020
1f00542
implemented method to mark as done
JustinnT Jan 31, 2020
3042ebf
Refractor code to follow java coding standards
JustinnT Jan 31, 2020
0165792
Deleted extra line
JustinnT Jan 31, 2020
0430f62
Refractor if-else statement
JustinnT Jan 31, 2020
e7d092d
add try-catch statement for exception handling
JustinnT Jan 31, 2020
2cf8d6c
added todo class inheriting from Task
JustinnT Feb 4, 2020
1ae1024
overloaded toString in Task and used that to print out Tasks instead.
JustinnT Feb 4, 2020
ca35d97
added new feature to add todo task
JustinnT Feb 4, 2020
37cb07d
overloaded printConfirmationMessage method in Printer class to print …
JustinnT Feb 4, 2020
c75238d
(incomplete) added events class to enable creation of new sub-type of…
JustinnT Feb 8, 2020
5c80014
added support for tracking of todo task
JustinnT Feb 8, 2020
4c80cb8
remove extra try catch statement
JustinnT Feb 8, 2020
4a5fc94
introduced constants for magic numbers
JustinnT Feb 8, 2020
76b2560
added deadline task
JustinnT Feb 8, 2020
2533ea0
changes constant names
JustinnT Feb 8, 2020
2bacb7a
added message for deadline and personalized printer
JustinnT Feb 8, 2020
ed507b4
added parser class to parse user input
JustinnT Feb 8, 2020
280e1a5
changed to static list to access outside of class
JustinnT Feb 8, 2020
b336949
added deadline class
JustinnT Feb 8, 2020
a5cdbc3
added functionality to at event type tasks
JustinnT Feb 8, 2020
109c613
personalized printing messages
JustinnT Feb 8, 2020
a8b00ed
added a new constant
JustinnT Feb 8, 2020
eb3d17c
refractor code
JustinnT Feb 8, 2020
e9104a1
git ignore
JustinnT Feb 8, 2020
4e1bd77
add functionalities to handle more errors
JustinnT Feb 8, 2020
2d96ff4
added comments
JustinnT Feb 8, 2020
5edc8b6
remove comment
JustinnT Feb 8, 2020
725c05c
testing for branch
JustinnT Feb 8, 2020
930d0c6
Merge branch 'master' into branch-Level-5_part2
JustinnT Feb 8, 2020
63f424b
test brach 2
JustinnT Feb 8, 2020
9761edc
Merge branch 'branch-Level-5_part2'
JustinnT Feb 8, 2020
e50b44d
add custom print message for exception handling
JustinnT Feb 9, 2020
254352e
update git ignore
JustinnT Feb 22, 2020
6451c9d
refractor code
JustinnT Feb 22, 2020
8c411ab
added delete functionality
JustinnT Feb 22, 2020
0069b3b
refractor printer class
JustinnT Feb 22, 2020
a28c87b
refractor printer class
JustinnT Feb 22, 2020
a629b3f
Added level 7 save
JustinnT Feb 22, 2020
540585f
Merge branch 'branch-Level-6'
JustinnT Feb 22, 2020
b5438f7
Merge branch 'branch-Level-7'
JustinnT Feb 22, 2020
8ed8add
refractor code
JustinnT Feb 23, 2020
44c81f8
Increment more OOP
JustinnT Feb 23, 2020
20bfe89
Merge branch 'A-MoreOOP'
JustinnT Feb 23, 2020
c8c0737
added find for level-9
JustinnT Feb 23, 2020
2cc378d
added A-JavaDoc
JustinnT Feb 23, 2020
627e158
Merge pull request #2 from JustinnT/branch-level-9
JustinnT Feb 23, 2020
82331b2
Merge branch 'master' of https://github.com/JustinnT/duke
JustinnT Feb 23, 2020
f42d5c9
Merge branch 'master' into A-JavaDoc
JustinnT Feb 23, 2020
1c3c54f
Merge pull request #3 from JustinnT/A-JavaDoc
JustinnT Feb 23, 2020
bb5dfa9
Merge branch 'master' of https://github.com/JustinnT/duke
JustinnT Feb 23, 2020
43b53d6
fix index out of bounds exception for find command
JustinnT Feb 23, 2020
0f0c99a
A-packages
JustinnT Feb 23, 2020
bea671f
Merge branch 'master' of https://github.com/JustinnT/duke
JustinnT Feb 24, 2020
b5b9c39
Moved into different packages
JustinnT Feb 24, 2020
ebc22c1
Set theme jekyll-theme-tactile
JustinnT Feb 24, 2020
83257dc
test user guide
JustinnT Feb 24, 2020
10826a5
Merge branch 'master' of https://github.com/JustinnT/duke
JustinnT Feb 24, 2020
92e89ce
refractor variable name to reflect more accurately on what Find does
JustinnT Feb 24, 2020
84523ee
added custom error message for done command
JustinnT Feb 24, 2020
111afbb
add user guide
JustinnT Feb 24, 2020
8a03770
Suppress warnings
JustinnT Feb 29, 2020
f34c442
Merge branch 'master' of https://github.com/JustinnT/duke
JustinnT Feb 29, 2020
e82c41f
Added content page for UG
JustinnT Mar 2, 2020
5f76081
Fix missing whitespace on '##' character
JustinnT Mar 2, 2020
48a8034
Fix formatting error
JustinnT Mar 2, 2020
2eb84ab
fix formatting error
JustinnT Mar 2, 2020
477c5d5
Fix more formatting error
JustinnT Mar 2, 2020
6743bcd
undo changes
JustinnT Mar 2, 2020
c56f850
Set theme jekyll-theme-architect
JustinnT Mar 2, 2020
adebdf5
Merge branch 'master' of https://github.com/JustinnT/duke
JustinnT Mar 3, 2020
02b0471
Removed utf 8 as windows cannot display it properly
JustinnT Mar 3, 2020
5ca80b4
Added custom delete error message
JustinnT Mar 3, 2020
4e1328c
Finished and removed todo comments
JustinnT Mar 3, 2020
98e313b
Remove todo comment
JustinnT Mar 3, 2020
ee23323
Updated UG to reflect changes in printing
JustinnT Mar 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 88 additions & 2 deletions src/main/java/Duke.java
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);
Copy link

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)


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();
Copy link

Choose a reason for hiding this comment

The 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();
}
}
66 changes: 66 additions & 0 deletions src/main/java/Printer.java
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();
}
}
23 changes: 23 additions & 0 deletions src/main/java/Storage.java
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<>();
Copy link

Choose a reason for hiding this comment

The 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;
Copy link

Choose a reason for hiding this comment

The 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.

}
}
}
25 changes: 25 additions & 0 deletions src/main/java/Task.java
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;
}
}