-
Notifications
You must be signed in to change notification settings - Fork 313
[Shirley] Duke Increments #447
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
Open
bitterg0d
wants to merge
42
commits into
nus-cs2103-AY1920S1:master
Choose a base branch
from
bitterg0d: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 14 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum 0112efe
Add sample checkstyle configuration
j-lum cfd6da7
Change file mode on `gradle` to be executable
j-lum 6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum a3ca5a4
Add configuration for console applications
j-lum 7b60e81
Merge pull request #13 from j-lum/javaexec
j-lum 69d98fe
Level-1
2cde05a
added Level-1, ACTUAL.TXT, EXPECTED.txt, input.txt, runtest.sh
6522dbc
Change in location of test-ui-text folder
e42b83c
added level 2
88723af
added level 3, added Task.java to represent Task
c708f13
added level 4 and 5, with error handling and separate class files to …
a526b71
added level-6
3ff017e
fixed printing error for list
27a6b76
Revert "fixed printing error for list"
51c544f
Revert "fixed printing error for list"
fee74d8
added Level-7
13c47ef
added Level-8
985ff1b
Merge branch 'branch-Level-7'
198f8fe
added level-9, with changes to level-8
345e316
added increments: A-MoreOOP, A-Packages
4c122a8
added test code folder
bb0807e
Merge branch 'gradle' of https://github.com/bitterg0d/duke
c4493e8
added gradle plugins: shadowjar
331d9c1
Added JavaDoc comments for code
5a0f754
Tweaked the code to comply with coding standard
ce5cb34
added javaFX plugin, completed 3/4 of GUI
cb6776e
added A-JavaFx and Level-10 GUI
ff8c0e0
added help guidance for users, packaged dialogbox/main/mainwindow int…
8a8d5ba
updated README.md user guide, added max width and padding of dialog box
5f7260e
resolved checkbox issue, updated jar version number
9818dd6
updated link of Ui to a working link
ba34f15
Set theme jekyll-theme-slate
bitterg0d 4597d26
Set theme jekyll-theme-slate
bitterg0d 8800c86
Set theme jekyll-theme-slate
bitterg0d 40fff66
Set theme jekyll-theme-slate
bitterg0d 7f54bc0
updated user guide
304706f
Merge branch 'master' of https://github.com/bitterg0d/duke
7c9ad7b
fixed typos in README.md
3d8bcd7
edited inline code
91c2f8e
edited README.md
3b91222
edited README.md
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 hidden or 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,50 @@ | ||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.time.DateTimeException; | ||
| import java.util.Date; | ||
|
|
||
| public class Deadline extends Task { | ||
|
|
||
| private SimpleDateFormat deadline; | ||
| protected String by; | ||
| private Date date; | ||
| protected int dd, mm, yyyy, hrs, min, time; | ||
|
|
||
| public Deadline(String description, String by) throws DateTimeException { | ||
| super(description); | ||
| this.by = by; | ||
| this.type = "D"; | ||
|
|
||
| this.deadline = new SimpleDateFormat("dd/MM/yyyy HHmm"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return this.type; | ||
| } | ||
|
|
||
| @Override | ||
| public String getBy() { | ||
| return this.by; | ||
| } | ||
|
|
||
| public String convertEventTime() throws ParseException, DateTimeException { | ||
|
|
||
| try { | ||
| date = deadline.parse(this.by); | ||
| return deadline.format(date); | ||
| } catch (ParseException exception) { | ||
| System.out.println("\u2639 OOPS!!! Please enter a valid deadline"); | ||
| } | ||
| return ""; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| try { | ||
| return "[D]" + super.toString() + " (by: " + convertEventTime() + ")"; | ||
| } catch (ParseException exception) { | ||
| return "Error"; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,208 @@ | ||
| import java.io.IOException; | ||
| import java.text.ParseException; | ||
| import java.util.Scanner; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Collection; | ||
|
|
||
| //import java.io.IOException; | ||
| //import java.text.ParseException; | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
|
|
||
| public class Duke { | ||
| public static void main(String[] args) { | ||
|
|
||
| private ArrayList<Task> list; | ||
| private Saved savedFile; | ||
| private Scanner scan; | ||
| final private static String LINE = "____________________________________________________________"; | ||
|
|
||
| public static void main(String[] args) throws IOException, ParseException { | ||
| new Duke("src/main/java/data.txt").run(); | ||
| } | ||
|
|
||
| public Duke(String filePath) throws IOException, ParseException { | ||
| scan = new Scanner(System.in); | ||
| savedFile = new Saved(filePath); | ||
| list = savedFile.loadData(); | ||
| } | ||
|
|
||
| public void run() throws IOException, ParseException { | ||
|
|
||
| final String GOT_IT = "Got it. I've added this task:"; | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| String cmd; | ||
|
|
||
| printIntro(); | ||
|
|
||
| Boolean isNotBye = true; | ||
| while(isNotBye) { | ||
| cmd = scan.nextLine(); | ||
| String cmdArr[] = cmd.split(" ", 2); | ||
| String firstWord = cmdArr[0]; | ||
|
|
||
| switch (firstWord) { | ||
| case "bye": | ||
| printLine(); | ||
| printDuke("Bye. Hope to see you again soon!"); | ||
| printLine(); | ||
| isNotBye = false; | ||
| break; | ||
|
|
||
| case "list": | ||
| printLine(); | ||
| if (list.isEmpty()) { | ||
| System.out.println(" There is nothing in your list."); | ||
| printLine(); | ||
| break; | ||
| } | ||
| printList(list); | ||
| break; | ||
|
|
||
| case "done": | ||
| printLine(); | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| int taskNum = Integer.valueOf(cmdArr[1]); | ||
| list.get(taskNum - 1).isDone(true); | ||
| printDuke("Nice! I've marked this task as done"); | ||
| System.out.println(" " + taskNum + ". [" + list.get(taskNum - 1).getStatusIcon() + "]" | ||
| + list.get(taskNum - 1).getDesc()); | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| printLine(); | ||
| break; | ||
|
|
||
| case "todo": | ||
| try { | ||
| String task = cmdArr[1]; | ||
| Todo todo = new Todo(task); | ||
| list.add(todo); | ||
|
|
||
| //output | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| printLine(); | ||
| printDuke(GOT_IT); | ||
| printDuke(todo.toString()); | ||
| printDuke("Now you have " + list.size() + " tasks in the list"); | ||
| printLine(); | ||
| } catch (ArrayIndexOutOfBoundsException exception) { | ||
| printLine(); | ||
| printDuke("\u2639 OOPS!!! The description of a todo cannot be empty."); | ||
| printLine(); | ||
| } | ||
| break; | ||
|
|
||
| case "deadline": | ||
| try { | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| String taskAndDate = cmdArr[1]; | ||
| String dl[] = taskAndDate.split("/", 2); | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| try { | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| String by = dl[1].substring(3); | ||
| Deadline deadline = new Deadline(dl[0], by); | ||
| list.add(deadline); | ||
| //output | ||
| printDuke(GOT_IT); | ||
| printDuke(deadline.toString()); | ||
| printDuke("Now you have " + list.size() + " tasks in the list"); | ||
| printLine(); | ||
| } catch (ArrayIndexOutOfBoundsException exception) { | ||
| printLine(); | ||
| printDuke("\u2639 OOPS!!! Please enter when the deadline is due"); | ||
| printLine(); | ||
| } | ||
| } catch (ArrayIndexOutOfBoundsException exception) { | ||
| printLine(); | ||
| printDuke("\u2639 OOPS!!! The description of a deadline cannot be empty."); | ||
| printLine(); | ||
| } | ||
| break; | ||
|
|
||
| case "event": | ||
| try { | ||
| String eventAndDate = cmdArr[1]; | ||
| String e[] = eventAndDate.split("/", 2); | ||
| try { | ||
| String at = e[1].substring(3); | ||
| Event event = new Event(e[0], at); | ||
| list.add(event); | ||
|
|
||
| //output | ||
| printLine(); | ||
| printDuke(GOT_IT); | ||
| printDuke(event.toString()); | ||
| printDuke("Now you have " + list.size() + " tasks in the list"); | ||
| printLine(); | ||
| } catch (ArrayIndexOutOfBoundsException exception) { | ||
| printLine(); | ||
| printDuke("\u2639 OOPS!!! Please enter when the event is happening"); | ||
| printLine(); | ||
| } | ||
| } catch (ArrayIndexOutOfBoundsException exception) { | ||
| printLine(); | ||
| printDuke("\u2639 OOPS!!! The description of an event cannot be empty."); | ||
| printLine(); | ||
| } | ||
| break; | ||
|
|
||
| case "delete": | ||
| try { | ||
| int deleteNum = Integer.valueOf(cmdArr[1]); | ||
| Task deletedTask = list.get(deleteNum - 1); | ||
| list.remove(deleteNum - 1); | ||
|
|
||
| printLine(); | ||
| printDuke("Noted. I've removed this task:"); | ||
| printDuke(deletedTask.toString()); | ||
| printDuke("Now you have " + list.size() + " tasks in the list"); | ||
| printLine(); | ||
| } catch (ArrayIndexOutOfBoundsException exception) { | ||
| printLine(); | ||
| printDuke("\u2639 OOPS!!! Please add the task number"); | ||
| printLine(); | ||
| } | ||
| break; | ||
|
|
||
| case "find": | ||
| String keyword = cmdArr[1]; | ||
| ArrayList<Task> matchingTasks = new ArrayList<>(); | ||
| for (Task task : list) { | ||
| if (task.getDesc().contains(keyword)) { | ||
| matchingTasks.add(task); | ||
| } | ||
| } | ||
| printList(matchingTasks); | ||
| break; | ||
| default: | ||
| printLine(); | ||
| printDuke("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
| printLine(); | ||
| } | ||
| } | ||
| savedFile.saveToFile(list); | ||
| } | ||
|
|
||
| public static void printIntro() { | ||
| /* | ||
|
bitterg0d marked this conversation as resolved.
Outdated
bitterg0d marked this conversation as resolved.
Outdated
|
||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| */ | ||
| printLine(); | ||
| System.out.println(" Hello! I'm Duke"); | ||
| System.out.println(" What can I do for you?"); | ||
| printLine(); | ||
| } | ||
| public static void printLine() { | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| System.out.println(" " + LINE); | ||
| } | ||
|
|
||
| public static void printDuke(String toPrint) { | ||
| System.out.println(" " + toPrint); | ||
| } | ||
| public void printList(ArrayList<Task> list) { | ||
| System.out.println(" Here are the tasks in your list:"); | ||
| for (int i = 0; i < list.size(); i++) { | ||
| Task task = list.get(i); | ||
| System.out.println(" " + (i + 1) + ". " + task.toString()); | ||
|
|
||
| } | ||
|
|
||
| printLine(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,45 @@ | ||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.time.DateTimeException; | ||
| import java.util.Date; | ||
| import java.time.LocalTime; | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
|
|
||
| public class Event extends Task { | ||
|
|
||
| protected String at; | ||
| private SimpleDateFormat eventTime; | ||
| private Date date; | ||
| //protected int dd, mm, yyyy, startTime, startHrs, startMin, endTime, endHrs, endMin; | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
|
|
||
| public Event(String description, String at) throws DateTimeException { | ||
| super(description); | ||
| this.at = at.trim(); | ||
| this.event = "event"; | ||
| this.type = "E"; | ||
|
|
||
| eventTime = new SimpleDateFormat("dd/MM/yyyy HHmm"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getType() { | ||
| return this.type; | ||
| } | ||
|
|
||
| @Override | ||
| public String getAt() { | ||
| return this.at; | ||
| } | ||
|
|
||
| public String convertEventTime() throws ParseException, DateTimeException { | ||
| this.date = eventTime.parse(this.at); | ||
| return this.eventTime.format(date); | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| try { | ||
| return "[E]" + super.toString() + " (at: " + convertEventTime() + ")"; | ||
| } catch (ParseException exception) { | ||
| return "Error"; | ||
|
bitterg0d marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,74 @@ | ||
| import java.text.ParseException; | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| import java.io.FileWriter; | ||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
|
|
||
| public class Saved { | ||
| private String filePath; | ||
|
|
||
| public Saved(String filePath) { | ||
| this.filePath = filePath; | ||
| } | ||
|
|
||
| public ArrayList<Task> loadData() throws FileNotFoundException, ParseException { | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| File file = new File(filePath); | ||
| Scanner scan = new Scanner(file); | ||
|
|
||
| ArrayList<Task> list = new ArrayList<>(); | ||
|
|
||
| while(scan.hasNext()) { | ||
| String[] text = scan.nextLine().split(" \\| ", 4); | ||
|
|
||
| Task t; | ||
|
|
||
| switch (text[0]) { | ||
| case "T": | ||
| t = new Todo(text[2]); | ||
| break; | ||
| case "D": | ||
| t = new Deadline(text[2], text[3]); | ||
| break; | ||
| case "E": | ||
| t = new Event(text[2], text[3]); | ||
| break; | ||
| default: | ||
| t = new Task(""); | ||
| break; | ||
| } | ||
|
|
||
| if (text[1].equals("1")) { | ||
| t.isDone = true; | ||
|
bitterg0d marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| list.add(t); | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| public void saveToFile(ArrayList<Task> list) throws IOException, ParseException { | ||
| FileWriter newFile = new FileWriter(this.filePath); | ||
| String listToFile = ""; | ||
| String s; | ||
|
|
||
| for (Task task: list) { | ||
| if (task instanceof Event) { | ||
| s = "E" + " | "+ task.getDone() + " | " + task.getDesc() + " | " + task.getAt(); | ||
|
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. Rather than having multiple if else statements, you can create an abstract method on the Task class that converts the task to a suitable storage format. |
||
| } else if (task instanceof Deadline) { | ||
| s = "D | " + task.getDone() + " | " + task.getDesc() + " | " + task.getBy(); | ||
| } else { | ||
| s = "T | " + task.getDone() + " | " + task.getDesc(); | ||
| } | ||
| newFile.write(s); | ||
| newFile.write("\n"); | ||
| } | ||
|
|
||
|
|
||
| newFile.write(listToFile); | ||
| newFile.flush(); | ||
| //newFile.close(); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.