-
Notifications
You must be signed in to change notification settings - Fork 200
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
[MichelleLiang0116] iP #200
Open
MichelleLiang0116
wants to merge
34
commits into
nus-cs2113-AY2223S2:master
Choose a base branch
from
MichelleLiang0116:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d2e1652
Level 0
tingyuliang0116 875214d
Level 0
tingyuliang0116 546d365
Level-1 Bye
tingyuliang0116 e5c4d7f
Level-1 Bye
tingyuliang0116 eaba19d
Level-1 List
tingyuliang0116 1097c11
Level-3 MarkAsDone
tingyuliang0116 2c0ac37
A-CodingStandard
tingyuliang0116 5e67ea1
Level-4
tingyuliang0116 0a7d6b0
Level-4
tingyuliang0116 0bd338f
Level-4
tingyuliang0116 dcbf7d7
Level-4
tingyuliang0116 fb2bb85
A-CodingStandard
tingyuliang0116 37ae4e7
A-CodingStandard
tingyuliang0116 341d75e
Level-4
tingyuliang0116 98769f2
A-CodingStandard
tingyuliang0116 166dbe5
A-CodingStandard
tingyuliang0116 90bb07f
Level-5
tingyuliang0116 e81c15c
Merge branch 'master' into branch-Level-5
tingyuliang0116 189960a
A-Exceptions
tingyuliang0116 53ca173
A-CodingStandard
tingyuliang0116 113e069
Level-6
tingyuliang0116 9922c6d
A-Collections
tingyuliang0116 3ab622a
Level-7
tingyuliang0116 379a9f8
A-Jar
tingyuliang0116 89744ec
A-MoreOOP
tingyuliang0116 aaf4920
Level-9
tingyuliang0116 8e2ca77
A-JavaDoc
tingyuliang0116 52f15f5
Merge pull request #2 from MichelleLiang0116/A-JavaDoc
MichelleLiang0116 892e5de
Level-9 change
tingyuliang0116 ffc90fd
Level-9 change
tingyuliang0116 2691a37
A-UserGuide
tingyuliang0116 aed8f4a
A-UserGuide
tingyuliang0116 8a238be
Change some function format
tingyuliang0116 649fcf5
Merge pull request #3 from MichelleLiang0116/A-JavaDoc
MichelleLiang0116 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public class Deadline extends Task { | ||
private final String by; | ||
|
||
/** | ||
* @param description description of the task | ||
* @param by the deadline of the task | ||
*/ | ||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
/** | ||
* @return convert to formatted string | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by:" + by + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import java.io.IOException; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
private final Storage storage; | ||
private final TaskList tasks; | ||
private final UI ui; | ||
private final Parser parser = new Parser(); | ||
|
||
/** | ||
* Create the Duke Object | ||
* @param filePath an String giving the base location of the file | ||
*/ | ||
public Duke(String filePath) throws IOException { | ||
ui = new UI(); | ||
storage = new Storage(filePath); | ||
this.tasks = new TaskList(storage.load()); | ||
} | ||
|
||
/** | ||
* Start to run the Duke application | ||
*/ | ||
public void run() throws IOException{ | ||
ui.showWelcome(); | ||
while (!parser.isExit()) { | ||
String fullCommand = ui.readCommand(); | ||
ui.showLine(); | ||
parser.parse(fullCommand); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
new Duke("duke.txt").run(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class Event extends Task { | ||
private final String from; | ||
private final String to; | ||
|
||
/** | ||
* @param description description of the task | ||
* @param from the start day of the task | ||
* @param to the end day of the task | ||
*/ | ||
public Event(String description, String from, String to) { | ||
super(description); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
/** | ||
* @return convert to formatted string | ||
* | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (from:" + from + " to:" + to + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: Duke | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class Parser { | ||
private boolean exit = false; | ||
|
||
/** | ||
* Parse the user command and store to the taskList if applicable | ||
* @param command the user input | ||
*/ | ||
public void parse(String command) throws IOException { | ||
if (command.equalsIgnoreCase("list")) { | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 0; i < TaskList.list.size(); i++) { | ||
System.out.println(i + 1 + "." + TaskList.list.get(i).toString()); | ||
} | ||
UI.showLine(); | ||
} else if (command.equalsIgnoreCase("bye")) { | ||
UI.showBye(); | ||
Storage.save(TaskList.list); | ||
this.exit = true; | ||
} else if (command.toLowerCase().contains("mark")) { | ||
try { | ||
String[] split = command.split("\\s+"); | ||
int toMark = Integer.parseInt(split[1]); | ||
if (split[0].equalsIgnoreCase("mark")) { | ||
TaskList.list.get(toMark - 1).markAsDone(); | ||
System.out.println("Nice! I've marked this task as done: "); | ||
} else { | ||
TaskList.list.get(toMark - 1).markAsUnDone(); | ||
System.out.println("OK, I've marked this task as not done yet: "); | ||
} | ||
System.out.println(TaskList.list.get(toMark - 1).toString() + '\n' + UI.lineBreak); | ||
} catch (NullPointerException e) { | ||
System.out.println("Item is not in list!"); | ||
} | ||
} else if (command.toLowerCase().contains("delete")) { | ||
String[] split = command.split("\\s+"); | ||
int toDelete = Integer.parseInt(split[1]); | ||
TaskList.taskListDelete(toDelete - 1); | ||
} else { | ||
Task t; | ||
if (command.toLowerCase().contains("deadline")) { | ||
try { | ||
String description = command.substring(command.indexOf(' ') + 1, command.indexOf('/')); | ||
String ddl = command.substring(command.indexOf('/') + 1); | ||
String by = ddl.replace("by", ""); | ||
t = new Deadline(description, by); | ||
TaskList.taskListAdd(t); | ||
} catch (StringIndexOutOfBoundsException e) { | ||
System.out.println("☹ OOPS!!! The description of a deadline cannot be empty." + '\n' + UI.lineBreak); | ||
} | ||
} else if (command.toLowerCase().contains("event")) { | ||
try { | ||
String substring = command.substring(command.indexOf(' ') + 1); | ||
String[] info = substring.split("/"); | ||
String from = info[1].replace("from", ""); | ||
String to = info[2].replace("to", ""); | ||
t = new Event(info[0], from, to); | ||
TaskList.taskListAdd(t); | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
System.out.println("☹ OOPS!!! The description of a event cannot be empty." + '\n' + UI.lineBreak); | ||
} | ||
} else if (command.toLowerCase().contains("todo")) { | ||
if (command.indexOf(' ') == -1) { | ||
System.out.println("☹ OOPS!!! The description of a todo cannot be empty." + '\n' + UI.lineBreak); | ||
} else { | ||
String description = command.substring(command.indexOf(' ') + 1); | ||
t = new Todo(description); | ||
TaskList.taskListAdd(t); | ||
} | ||
} else if (command.toLowerCase().contains("find")) { | ||
String substring = command.substring(command.indexOf(' ') + 1); | ||
ArrayList<Task> result=new ArrayList<>(); | ||
for(Task k:TaskList.list){ | ||
if(k.description.contains(substring)){ | ||
result.add(k); | ||
} | ||
} | ||
System.out.println("Here are the matching tasks in your list:"); | ||
for(int i=0;i<result.size();i++){ | ||
System.out.println(i + 1 + "." + result.get(i).toString()); | ||
} | ||
UI.showLine(); | ||
} else { | ||
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(" + '\n' + UI.lineBreak); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return check if the user want to stop the program | ||
*/ | ||
public boolean isExit() { | ||
return exit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class Storage { | ||
public static String filePath; | ||
|
||
public Storage(String path) { | ||
this.filePath = path; | ||
} | ||
|
||
public static String load() { | ||
return filePath; | ||
} | ||
|
||
/** | ||
* to save the taskList to txt file | ||
* | ||
* @param list the whole taskList created by user | ||
*/ | ||
public static void save(ArrayList<Task> list) throws IOException { | ||
FileWriter writer = new FileWriter(filePath, false); | ||
for (int i = 0; i < list.size(); i++) { | ||
writer.write(list.get(i).toString()); | ||
writer.write("\r\n"); | ||
} | ||
writer.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
public class Task { | ||
public final String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
/** | ||
* @return the Icon of current task | ||
*/ | ||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
/** | ||
* Mark the task to done | ||
*/ | ||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
/** | ||
* Mark the task to unDone | ||
*/ | ||
public void markAsUnDone() { | ||
this.isDone = false; | ||
} | ||
|
||
/** | ||
* @return convert to formatted string | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "[" + getStatusIcon() + "] " + description; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Inheritance to split task types is well done.