-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Wang Guanlin] iP #468
Open
WangGLJoseph
wants to merge
86
commits into
nus-cs2103-AY2122S1:master
Choose a base branch
from
WangGLJoseph: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
[Wang Guanlin] iP #468
Changes from 43 commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
d839859
Add Gradle support
ab74434
Level-1: Added Greet, Echo, Exit functions for Duke
WangGLJoseph c8163cf
Included gitignore file, ignore all files with .class extension
WangGLJoseph 7f6a9e4
Level-2: Added Add, List functions for Duke
WangGLJoseph 073b8bc
Created a Task class to represent tasks added by user
WangGLJoseph 94a2613
Changed Duke.java to represent userInputs as an ArrayList of Task obj…
WangGLJoseph 29a7b43
Removed deprecated code representing userInputs as an ArrayList of St…
WangGLJoseph 86734d8
Updated scanner to read userInput by using next() instead of nextLine()
WangGLJoseph 0704af3
Level-3: Added Mark as Done function for Duke
WangGLJoseph 840767d
Added field for task type and getter method for task type icon
WangGLJoseph bdeaad4
Updated instantiation of Task objects to include a taskType parameter
WangGLJoseph a792272
Abstracted out logic for beautifying task and list
WangGLJoseph 1327162
Updated scanner to use nextLine after first command has been checked
WangGLJoseph 541a1dd
Added constructor for Task that took in an additional string as remin…
WangGLJoseph c48c98d
Updated todo and deadline cases to be recognizable as userInput
WangGLJoseph 57a57d3
Added task reminder for Deadline tasks
WangGLJoseph 5b64f0e
Removed unnecesary use of delimiter for Deadline tasks
WangGLJoseph 213d350
Updated listBeautify to use taskBeautify method
WangGLJoseph ff40331
Level-4: Added ToDos, Events, Deadlines functions for Duke
WangGLJoseph 23a7854
Updated to use Inheritance to support multiple task types (ToDo, Even…
WangGLJoseph 20904d1
Fixed bug where type of Event was displayed as [D]
WangGLJoseph abba5bc
A-TextUiTesting: Used the input/output redirection technique to semi-…
WangGLJoseph 582d814
Removed deprecated method TaskBeautify() from Duke
WangGLJoseph 0e724a6
Added DukeException to handle errors in Duke regarding invalid user i…
WangGLJoseph f854a11
Level-5: Added exceptions for unknown and incomplete user inputs
WangGLJoseph 153032a
Level-6: Added Delete function to Duke, tasks stored in ArrayList<Task>
WangGLJoseph 287a6b4
Updated text-ui-test to work with Duke Level-6
WangGLJoseph a008ab8
Change indentation for switch case to follow module coding standards
WangGLJoseph f2e7526
Add duke.txt with relative filePath
WangGLJoseph 1a95507
Update Duke with filePath to duke.txt
WangGLJoseph 51f6c23
Handle creation of folder and file if not already present
WangGLJoseph 685755b
Add functinality to write to duke.txt
WangGLJoseph 8688ae6
Add skeletal method for copying from duke.txt and parsing it
WangGLJoseph b12e45e
Updated constructor of various task types
WangGLJoseph 845d1b1
Revert constructor of various task types
WangGLJoseph 6da91b1
Add parse method to convert duke.txt to taskArrayList
WangGLJoseph 54b588f
Fix bug where parse() was called twice incorrectly
WangGLJoseph d0a5a2e
Level-7: Add Save and Load duke.txt for Duke
WangGLJoseph bfb6cad
Update Deadline and Event to parse task description as string of date
WangGLJoseph 609beb1
Level-8: Add Dates and Times functionality to Duke
WangGLJoseph ee37691
Increment Duke display level
WangGLJoseph 281a595
Merge branch 'branch-Level-8'
WangGLJoseph 9e9109a
Add skeletal classes for more OOP
WangGLJoseph 7d0c2ff
Update skeletal class files to make Duke more OOP
WangGLJoseph 6415efd
Put all classes into cs2103.duke package
WangGLJoseph 1195f8d
Add JUnit Tests for Duke
WangGLJoseph 9a5e6fc
Update duke.txt initialisation to enable use of .jar files
WangGLJoseph c276a32
Add complete JavaDoc for all classes in Duke
WangGLJoseph 5524ba8
Remove unnecessary use of the 'this' keyword
WangGLJoseph c72dbd8
Level-9: Add find function for Duke
WangGLJoseph 13d56db
Merge branch 'branch-A-CodingStandard'
WangGLJoseph 596cb63
Merge branch 'branch-Level-9'
WangGLJoseph d6af729
Update README.md
WangGLJoseph e054745
Merge branch 'master' of https://github.com/WangGLJoseph/ip
WangGLJoseph 0c633a2
Merge branch 'add-gradle-support' into branch-A-Gradle
WangGLJoseph 613f9ce
Add DukeLauncher as part of JavaFX basics
WangGLJoseph 60e607a
Update README.md
WangGLJoseph 379ba30
Extract GUI logic out of Duke and into Main
WangGLJoseph 1ac4e8f
Update README.md
WangGLJoseph 40f61c6
Create new package for controllers
WangGLJoseph 04bbebc
Merge branch 'master' of https://github.com/WangGLJoseph/ip
WangGLJoseph 53dafd7
Level-10: Add GUI for Duke
WangGLJoseph 8daf0b5
Merge branch 'branch-Level-10'
WangGLJoseph f83d529
Update Duke to use GUI
WangGLJoseph 9c7e428
Set font in GUI as Courier New
WangGLJoseph b5c3742
Make Duke wait before closing the window
WangGLJoseph 9821713
Add assertions for key assumptions in the code
WangGLJoseph 3638fd6
Update method header comments to follow the coding standard
WangGLJoseph 6af29d8
Update DialogBox to display more text
WangGLJoseph a70840f
TaskList class: Apply SLAP to shorten methods of adding tasks
WangGLJoseph c8a852a
Update .gitignore to ignore data/duke.txt
WangGLJoseph 1e509d0
Remove data within data/duke.txt
WangGLJoseph bf8166f
DukeParser class: Apply SLAP to shorten methods of parsing data
WangGLJoseph 0a6303e
Merge pull request #2 from WangGLJoseph/branch-A-Assertions
WangGLJoseph 1d7cac7
Merge branch 'master' of https://github.com/WangGLJoseph/ip
WangGLJoseph b067a25
Merge branch 'master' into branch-A-CodeQuality
WangGLJoseph 5721b1c
Merge pull request #3 from WangGLJoseph/branch-A-CodeQuality
WangGLJoseph e083605
Merge branch 'master' of https://github.com/WangGLJoseph/ip
WangGLJoseph 75661c5
Add functionality to undo the last undo-able command
WangGLJoseph 7f59eb6
Add Ui.png
WangGLJoseph 49dca7b
Update user guide for Duke
WangGLJoseph e010b92
Set theme jekyll-theme-time-machine
WangGLJoseph 5430e9f
Update formatting in user guide
WangGLJoseph 86a2f73
Merge branch 'master' of https://github.com/WangGLJoseph/ip
WangGLJoseph 4a7a59b
Remove emojis
WangGLJoseph cdb67d8
Update goodbye message
WangGLJoseph 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
*.class |
Empty file.
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,19 @@ | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
protected LocalDate date; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
this.date = LocalDate.parse(by); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("yyyy MM dd")) + ")"; | ||
} | ||
} |
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,66 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
/** | ||
* This class encapsulates a Duke chat-bot. | ||
*/ | ||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
private static final int lv = 8; | ||
private static final String[] features = { | ||
"", | ||
"Greet, Echo, Exit", | ||
", Add, List", | ||
", Mark as Done", | ||
", ToDos, Events, Deadlines", | ||
", Handle Errors", | ||
", Delete", | ||
", Save", | ||
", Dates and Times" | ||
}; | ||
private static ArrayList<Task> taskArrayList = new ArrayList<>(); | ||
private static final String dukeFilePath = "./data/duke.txt"; | ||
private Storage storage; | ||
private TaskList tasks; | ||
private Ui ui; | ||
|
||
public Duke(String dukeFilePath) { | ||
ui = new Ui(); | ||
storage = new Storage(dukeFilePath); | ||
try { | ||
tasks = new TaskList(storage.load()); | ||
} catch (DukeException | IOException e) { | ||
ui.showLoadingError(); | ||
tasks = new TaskList(); | ||
} | ||
} | ||
} | ||
|
||
public void run() throws IOException { | ||
ui.showWelcome(); | ||
boolean canExit = false; | ||
// Scanner to read user inputs | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
while (!canExit) { | ||
String userInput = scanner.next(); | ||
try { | ||
if (userInput.equals("bye")) { // user inputs "bye", set canExit to true and Exit | ||
canExit = true; | ||
String temp = tasks.listBeautify(taskArrayList); | ||
storage.overwriteFile(dukeFilePath, temp); | ||
ui.showGoodbye(); | ||
} else { // check first input | ||
ui.handleInput(scanner, userInput, tasks); | ||
} | ||
} catch (DukeException | IOException e) { | ||
e.printStackTrace(); // print stack trace for e | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws IOException, DukeException { | ||
new Duke("data/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,13 @@ | ||
public class DukeException extends Exception { | ||
private static String msg; | ||
|
||
public DukeException(String errorMessage) { | ||
super(errorMessage); | ||
msg = errorMessage; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ("Oh No! I do not understand your input due to the following problem:\n" + msg); | ||
} | ||
} |
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,106 @@ | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class DukeParser { | ||
private String filePath; | ||
|
||
public DukeParser(String dukeFilePath) { | ||
this.filePath = dukeFilePath; | ||
} | ||
|
||
/** | ||
* This method copies the contents of the file from filePath and | ||
* converts them into Task objects into the taskArrayList with the | ||
* help of the parse() method. | ||
* | ||
* @return taskArrayList the ArrayList to copy the information to | ||
* @throws IOException if filePath does not exist | ||
*/ | ||
public ArrayList<Task> copyFileContents() throws IOException { | ||
File f = new File(this.filePath); // create a File for the given file path | ||
Scanner s = new Scanner(f); // create a Scanner using the File as the source | ||
StringBuilder targetBuilder = new StringBuilder(); | ||
while (s.hasNext()) { | ||
targetBuilder.append(s.nextLine()).append("\n"); | ||
} | ||
|
||
return parse(targetBuilder.toString()); | ||
} | ||
|
||
/** | ||
* This method parses the string copied from duke.txt and converts them into task objects | ||
* into the taskArrayList. | ||
* | ||
* @param toParse the string to parse | ||
* @return a taskArrayList made up of tasks | ||
*/ | ||
public static ArrayList<Task> parse(String toParse) { | ||
ArrayList<Task> result = new ArrayList<>(); | ||
Scanner ps = new Scanner(toParse); // passes whole file into the scanner | ||
// [[T][ ] 1, [E][ ] 2 (at: 2), [D][ ] 3 (by: 3)] | ||
while (ps.hasNextLine()) { | ||
String nLine = ps.nextLine(); // parse one line at a time | ||
int ref = 3; // reference point | ||
char taskType = nLine.charAt(ref); | ||
boolean isDone = nLine.charAt(ref + 3) == 'X'; | ||
int strLength = nLine.length(); | ||
switch (taskType) { | ||
case 'T': | ||
String todoName = nLine.substring(ref + 5, strLength); | ||
Task newestTodo = new ToDo(todoName); | ||
if (isDone) { | ||
newestTodo.markAsDone(); | ||
} | ||
result.add(newestTodo); | ||
break; | ||
case 'D': | ||
String deadlineInfo = nLine.substring(ref + 5, strLength); | ||
String[] arrD = deadlineInfo.split("\\(by: ", 2); | ||
String deadlineName = arrD[0]; | ||
String deadlineReminder = arrD[1].substring(0, arrD[1].length() - 1); | ||
deadlineReminder = parseDate(deadlineReminder); | ||
Task newestDeadline = new Deadline(deadlineName, deadlineReminder); | ||
result.add(newestDeadline); | ||
if (isDone) { | ||
newestDeadline.markAsDone(); | ||
} | ||
break; | ||
case 'E': | ||
String eventInfo = nLine.substring(ref + 5, strLength); | ||
String[] arrE = eventInfo.split("\\(at: ", 2); | ||
String eventName = arrE[0]; | ||
String eventReminder = arrE[1].substring(0, arrE[1].length() - 1); | ||
eventReminder = parseDate(eventReminder); | ||
Task newestEvent = new Event(eventName, eventReminder); | ||
result.add(newestEvent); | ||
if (isDone) { | ||
newestEvent.markAsDone(); | ||
} | ||
break; | ||
default: | ||
System.out.println("Unknown input"); | ||
break; | ||
} | ||
} | ||
System.out.println("result is: " + result); | ||
return result; | ||
} | ||
|
||
/** | ||
* Parses input string in the format "yyyy MM dd" and returns it in the format | ||
* "YYYY-MM-DD". | ||
* | ||
* @param input string in format "MMM d yyyy" | ||
* @return string in format "YYYY-MM-DD" | ||
*/ | ||
public static String parseDate(String input) { | ||
String year = input.substring(0, 4); | ||
String month = input.substring(5, 7); | ||
String day = input.substring(8, 10); | ||
|
||
return year + "-" + month + "-" + day; | ||
} | ||
|
||
} |
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,19 @@ | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class Event extends Task { | ||
|
||
protected String at; | ||
protected LocalDate date; | ||
|
||
public Event(String description, String at) { | ||
super(description); | ||
this.at = at; | ||
this.date = LocalDate.parse(at); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (at: " + date.format(DateTimeFormatter.ofPattern("yyyy MM dd")) + ")"; | ||
} | ||
} |
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,59 @@ | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.io.File; | ||
|
||
public class Storage { | ||
private static ArrayList<Task> taskArrayList = new ArrayList<>(); | ||
private final String filePath; | ||
|
||
public Storage(String dukeFilePath) { | ||
this.filePath = dukeFilePath; | ||
} | ||
|
||
public ArrayList<Task> load() throws IOException { | ||
// load the data from the hard disk for dukeFile | ||
File dukeFile = new File(filePath); | ||
|
||
// creates directory if it does not exist | ||
if (dukeFile.mkdir()) { | ||
System.out.println("folder: 'data/' has been created"); | ||
} | ||
// creates file if it does not exist | ||
if (dukeFile.createNewFile()) { | ||
System.out.println("'duke.txt' has been created in the 'data/' folder "); | ||
} | ||
|
||
DukeParser p = new DukeParser(filePath); | ||
return p.copyFileContents(); | ||
} | ||
|
||
/** | ||
* This method overwrites the file. | ||
* | ||
* @param filePath the path to the file to append to | ||
* @param textToAppend the text to append | ||
* @throws IOException if filePath does not exist | ||
*/ | ||
|
||
public void overwriteFile(String filePath, String textToAppend) throws IOException { | ||
FileWriter fw = new FileWriter(filePath, false); // create a FileWriter in append mode | ||
fw.write(textToAppend); | ||
fw.close(); | ||
} | ||
|
||
/** | ||
* This method appends to the file instead of overwrites. | ||
* | ||
* @param filePath the path to the file to append to | ||
* @param textToAppend the text to append | ||
* @throws IOException if filePath does not exist | ||
*/ | ||
|
||
public void appendToFile(String filePath, String textToAppend) throws IOException { | ||
FileWriter fw = new FileWriter(filePath, true); // create a FileWriter in append mode | ||
fw.write(textToAppend); | ||
fw.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,65 @@ | ||
/** | ||
* This class encapsulates a Task object. | ||
*/ | ||
|
||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
protected String taskType; | ||
protected String reminder; | ||
|
||
/** | ||
* Creates a task with the specified description, isDone false by default. | ||
* @param description description of task | ||
* | ||
*/ | ||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
/** | ||
* Getter method for status using isDone | ||
* | ||
* @return an icon 'X' if complete, space if otherwise | ||
*/ | ||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
/** | ||
* Getter method for type of task using taskType. | ||
* | ||
* @return an icon representing the type of the task (T, D, E) | ||
*/ | ||
public String getTypeIcon() { | ||
return (this.taskType == "todo" ? "T" : | ||
this.taskType == "deadline" ? "D" : | ||
this.taskType == "event" ? "E" : "NONE"); | ||
} | ||
|
||
/** | ||
* Getter method for task reminder | ||
* | ||
* @return the string reminder for the task | ||
*/ | ||
public String getReminder() { | ||
return this.reminder; | ||
} | ||
|
||
/** | ||
* Setter method for isDone of a Task object | ||
*/ | ||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
/** | ||
* Returns string representation of Task. | ||
* | ||
* @return string representation of Task | ||
*/ | ||
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.
Would it be possible to extract some of the code into another function to reduce code repetition and length of the parse method?