-
Notifications
You must be signed in to change notification settings - Fork 19
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
Level 1 to 3 (Week 2) #1
Open
tototto
wants to merge
86
commits into
nus-tic4001-AY2021S1:master
Choose a base branch
from
tototto: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 4 commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
3b19ba1
Add Gradle support
269e3ff
Level 1 to 3
tototto 0f09980
Finished Level 4
tototto d20f84a
A-TextUiTesting
tototto eeb75ba
A-CodingStandard
tototto 5d75ff9
branch-Level-5
tototto f6cdbf9
Merge tag 'branch-Level-5'
tototto c5d61c0
Made Task abstract
9624640
Merge A-AbstractClasses increment with Master
a75fcee
build.gradle: Update version to 8.29
61b84e7
Completed A-CodeQuality
fe09317
Merging branch-A-CodeQuality with Master
dc20b21
created Packages for Duke and re-solved Shell Script issues for Testing
73953a7
Merged branch-A-Packages with Master
1be5731
completed branch-Level-6
365f5a8
Merge pull request #1 from tototto/branch-Level-6
tototto 7a2fa8a
branch-Level-7 added File IO operation
2ee965d
added demonstration of using displayHandler to print messages for Rea…
a28ce65
branch-A-JavaDoc added some java docs
4e3bb94
Merge branch 'branch-Level-7'
00f14ef
completed A-MoreOOP, refactored code out to individual classes/compon…
1471017
completed branch-Level-9
4578c64
add Junit testcases
7c0bebd
Merge pull request #2 from tototto/branch-A-JUnit
tototto 02fc569
resolve merge conflict when merging master to branch-Level-9
cbe13a9
Merge pull request #3 from tototto/branch-Level-9
tototto a1a2066
commiting
fd6ead5
resolved local merge conflict with the version from Git Pull
ef20fc2
Created User Guide
tototto 9991603
Changed format
tototto bd7293b
Update README.md
tototto 7adebbe
Set theme jekyll-theme-slate
tototto 0bea941
Update README.md
tototto f134e03
Update README.md
tototto d54b09a
add gradle support from upstream
673a84c
Merge branch 'branch-A-Gradle'
839b98c
Merge branch 'master' of https://github.com/tototto/ip
9c940b8
introduced JavaFX
859a1bc
Implement working JavaFX UI
1ec8b9a
competed working JavaFX for Duke
8d1655d
Finish building FXML
0ec3d22
refactor into packages of FXML implementation
a7badc2
Merge branch 'branch-Level-10'
c349451
attempted to improve coding standard
fe0fd54
added A Stricter Coding Standard
1250f58
Create yml file for CI
tototto 5848c81
fixed yml syntax
tototto 76b918f
added an extension from category C (C-Help)
bb13edd
Merge branch 'master' of https://github.com/tototto/ip
b537754
updated checkstyle.xml to remove suppresion filter dependency
dd66300
added suppresion filter dependency back and created suppression.xml
b72459a
fixed checkstyle in FileManager
897efa7
fixed remaning checkstyle error found in CI
1d01229
pushing code with junit issue to repo so others can take a look
6cb4a7a
fixed issue where project cannot build Junit using Gradle
c3ebc0c
fixed checkstyle for Junit
0146c6b
Update README.md
tototto 456113a
Update README.md
tototto db1c81f
Update README.md
tototto 3c390c0
Update README.md
tototto e0a403d
Set theme jekyll-theme-merlot
tototto 25c4f7f
Create UserGuide.md
tototto d64cd84
Create DeveloperGuide.md
tototto c53b4b1
Update UserGuide.md
tototto f106611
Update README.md
tototto 6ddfe40
Update README.md
tototto 52be408
Update UserGuide.md
tototto bab01ec
Create image
tototto dd338ae
Add files via upload
tototto 378bdd5
Delete image
tototto ae407e1
Update DeveloperGuide.md
tototto 6f52eee
Update DeveloperGuide.md
tototto 624fc46
Update DeveloperGuide.md
tototto 776906a
Update DeveloperGuide.md
tototto 916bef1
Update DeveloperGuide.md
tototto 282404e
Update DeveloperGuide.md
tototto d7af8a7
Update DeveloperGuide.md
tototto a948fa5
Update DeveloperGuide.md
tototto 77d1975
Update DeveloperGuide.md
tototto 2d62376
Update DeveloperGuide.md
tototto dc753fa
added Ui.png to meet submission requirmenet
tototto 474e3c2
Update README.md
tototto a879088
Update README.md
tototto 283a704
Update README.md
tototto 9e5ecac
Update README.md
tototto 435a4b8
Update README.md
tototto 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//import jdk.internal.util.xml.impl.Input; | ||
|
||
public class CommandHandler { | ||
|
||
DisplayHandler DisplayUnit = new DisplayHandler(); | ||
InputParser InputUnit = new InputParser(); | ||
|
||
public void checkCommandType(String KeyWord, String Body, ListHandler List) { | ||
|
||
KEYWORD keyword = KEYWORD.valueOf(KeyWord.toUpperCase()); | ||
|
||
try{ | ||
|
||
switch(keyword){ | ||
case TODO: | ||
List.addToDo(Body); | ||
Task todoTaskAdded = (Task) List.GetList().lastElement(); | ||
DisplayUnit.ShowTaskAdded(List.GetList().size(), todoTaskAdded); | ||
break; | ||
|
||
case DEADLINE: | ||
String deadlineBody = InputUnit.extractDeadlineBody(Body); | ||
String deadlineByDate = InputUnit.extractDeadlineByDay(Body); | ||
String deadlineByTime = InputUnit.extractDeadlineByTime(Body); | ||
List.addDeadline(deadlineBody, deadlineByDate, deadlineByTime); | ||
Task deadlineTaskAdded = (Task) List.GetList().lastElement(); | ||
DisplayUnit.ShowTaskAdded(List.GetList().size(), deadlineTaskAdded); | ||
break; | ||
|
||
case EVENT: | ||
String eventBody = InputUnit.extractEventBody(Body); | ||
String eventDay = InputUnit.extractEventAtDay(Body);; | ||
String eventTime = InputUnit.extractEventAtTime(Body); | ||
List.addEvent(eventBody, eventDay, eventTime); | ||
Task EventTaskAdded = (Task) List.GetList().lastElement(); | ||
DisplayUnit.ShowTaskAdded(List.GetList().size(), EventTaskAdded); | ||
break; | ||
|
||
case LIST: | ||
DisplayUnit.DisplayList(List.GetList()); | ||
break; | ||
|
||
case DONE: | ||
Task task = List.UpdateListItem(Body); | ||
DisplayUnit.DisplayChanges(task); | ||
break; | ||
|
||
case BYE: | ||
DisplayUnit.ProgramEnding(); | ||
System.exit(0); | ||
break; | ||
} | ||
|
||
} catch (Exception e){ | ||
DisplayUnit.DisplayInvalidInput(); | ||
} | ||
} | ||
} |
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,18 @@ | ||
import java.util.Date; | ||
|
||
public class Deadline extends Task { | ||
|
||
public Deadline(String description, String by, String time) { | ||
super(description); | ||
this.by = by; | ||
this.time = time; | ||
} | ||
|
||
protected String by; | ||
protected String time; | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + "(by: " + by + " " + time +")"; | ||
} | ||
} |
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,116 @@ | ||
import java.util.Vector; | ||
import java.util.*; | ||
|
||
public class DisplayHandler { | ||
|
||
final private String LOGO_ICON = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
||
final private String GREETING_MSG = " Hello! I'm Duke\n What can I do for you?"; | ||
final private String SUCCESS_MSG = " Got it. I've added this task: "; | ||
final private String LIST_MSG = " Here are the tasks in your list:"; | ||
final private String LIST_NUMBER = " Now you have %d tasks in the list.\n"; | ||
final private String DONE_MSG = " Nice! I've marked this task as done: "; | ||
final private String INVALID_INPUT_MSG = " That input was invalid! Try Again!"; | ||
final private String GOODBYE_MSG = " Bye. Hope to see you again soon!"; | ||
final private String LINE_DIVIDER = "----------------------------------------"; | ||
|
||
private void Greeter(){ | ||
System.out.println(GREETING_MSG); | ||
} | ||
|
||
private void Goodbye(){ | ||
System.out.println(GOODBYE_MSG); | ||
} | ||
|
||
private void Divider(){ | ||
System.out.println(LINE_DIVIDER); | ||
} | ||
|
||
private void Logo(){ | ||
System.out.println(LOGO_ICON); | ||
} | ||
|
||
private void Success(){ | ||
System.out.println(SUCCESS_MSG); | ||
} | ||
|
||
private void InvalidInput(){ | ||
System.out.println(INVALID_INPUT_MSG); | ||
} | ||
|
||
private void ShowListMsg() { System.out.println(LIST_MSG); } | ||
|
||
public void DisplayNumAddedTask(int listNum) { | ||
System.out.printf(LIST_NUMBER, listNum); | ||
} | ||
|
||
public void Done(){ | ||
System.out.println(DONE_MSG); | ||
} | ||
|
||
public void DisplayIndividualTask(Task task){ | ||
System.out.println(" " + task); | ||
} | ||
|
||
private void ListResult(Vector result){ | ||
|
||
ShowListMsg(); | ||
Iterator iter = result.iterator(); | ||
|
||
for(int i = 0; iter.hasNext(); i++){ | ||
int currIndex = i + 1 ; | ||
Task element = (Task)iter.next(); | ||
System.out.println(" " + currIndex + "." + element); | ||
} | ||
} | ||
|
||
public void DisplayInvalidInput(){ | ||
InvalidInput(); | ||
} | ||
|
||
public void DisplayChanges(Task task) { | ||
Divider(); | ||
try{ | ||
task.getStatusIcon(); // check if exception will be thrown, this line has no functional usage | ||
|
||
Done(); | ||
System.out.println(task); | ||
|
||
} catch (NullPointerException e) { | ||
InvalidInput(); | ||
} | ||
Divider(); | ||
} | ||
|
||
public void DisplayList(Vector result) { | ||
Divider(); | ||
ListResult(result); | ||
Divider(); | ||
} | ||
|
||
public void ShowTaskAdded(int ListNum, Task task){ | ||
Divider(); | ||
Success(); | ||
DisplayIndividualTask(task); | ||
DisplayNumAddedTask(ListNum); | ||
Divider(); | ||
} | ||
|
||
public void ProgramOpening(){ | ||
// User Interface Display Section | ||
Divider(); | ||
Logo(); | ||
Greeter(); | ||
Divider(); | ||
} | ||
|
||
public void ProgramEnding(){ | ||
Divider(); | ||
Goodbye(); | ||
Divider(); | ||
} | ||
} |
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,30 @@ | ||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
// Instantiate program components | ||
DisplayHandler DisplayUnit = new DisplayHandler(); | ||
InputHandler InputUnit = new InputHandler(); | ||
InputParser Parser = new InputParser(); | ||
ListHandler List = new ListHandler(); | ||
CommandHandler Command = new CommandHandler(); | ||
|
||
// Uses a Facade to Manage Individual Modular Components | ||
DisplayUnit.ProgramOpening(); | ||
|
||
while(true) { | ||
|
||
// Get User Input | ||
String Input = InputUnit.getUserInput(); | ||
// Parse User Input | ||
String Keyword = Parser.extractKeyWord(Input); | ||
String Body = Parser.extractKeyWordBody(Input, Keyword); | ||
|
||
// If Input is not recognised Keyword | ||
if(Parser.checkIfKeyWord(Keyword) == false) | ||
DisplayUnit.DisplayInvalidInput(); | ||
// If Input is a recognised Keyword | ||
else | ||
Command.checkCommandType(Keyword, Body, List); | ||
} | ||
} | ||
} |
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,16 @@ | ||
public class Event extends Task{ | ||
|
||
public Event(String description, String at, String timePeriod) { | ||
super(description); | ||
this.at = at; | ||
this.timePeriod = timePeriod; | ||
} | ||
|
||
protected String at; | ||
protected String timePeriod; | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + "(at: " + at + " " + timePeriod +")"; | ||
} | ||
} |
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 @@ | ||
import java.util.Scanner; | ||
|
||
public class InputHandler { | ||
|
||
static private Scanner fromInputStream = new Scanner(System.in); | ||
|
||
public String getUserInput(){ | ||
|
||
String command = fromInputStream.nextLine(); | ||
|
||
return command; | ||
} | ||
} |
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,79 @@ | ||
public class InputParser { | ||
|
||
// Check if First Word is Keyword | ||
public boolean checkIfKeyWord(String Input) { | ||
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. if is boolean, hasKeyword/isKeyword would be a better naming? InputParser.isKeyword("abc"). 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. Yes. Indeed it would be. Thank you. |
||
|
||
try { | ||
KEYWORD.valueOf(Input.toUpperCase()); | ||
return true; | ||
|
||
} catch (IllegalArgumentException e) { | ||
return false; | ||
} | ||
} | ||
|
||
// Extract Keyword from Input | ||
public String extractKeyWord(String Input) { | ||
String[] Array = Input.split(" "); | ||
return Array[0]; | ||
} | ||
|
||
// Extract Body from Input | ||
public String extractKeyWordBody(String Input, String keyword) { | ||
try { | ||
return Input.replaceFirst(keyword, ""); | ||
|
||
} catch(ArrayIndexOutOfBoundsException e){ // May not be used anymore | ||
return null; | ||
} | ||
} | ||
// For Deadlines | ||
public String extractDeadlineBody(String DeadlineInput){ | ||
int indx = DeadlineInput.indexOf("/by"); | ||
return DeadlineInput.substring(0, indx); | ||
} | ||
|
||
public String extractDeadlineByDay(String DeadlineInput){ | ||
int indx = DeadlineInput.indexOf("/by"); | ||
String by = DeadlineInput.substring(indx, DeadlineInput.length()); | ||
String[] array = by.split(" "); | ||
return array[1]; | ||
} | ||
|
||
public String extractDeadlineByTime(String DeadlineInput){ | ||
try{ | ||
int indx = DeadlineInput.indexOf("/by"); | ||
String by = DeadlineInput.substring(indx); | ||
String[] array = by.split(" "); | ||
return array[2]; | ||
}catch (Exception e) | ||
{ | ||
return ""; | ||
} | ||
} | ||
// For Events | ||
public String extractEventBody(String EventInput){ | ||
int indx = EventInput.indexOf("/at"); | ||
return EventInput.substring(0, indx); | ||
} | ||
|
||
public String extractEventAtDay(String EventInput){ | ||
int indx = EventInput.indexOf("/at"); | ||
String by = EventInput.substring(indx, EventInput.length()); | ||
String[] array = by.split(" "); | ||
return array[1]; | ||
} | ||
|
||
public String extractEventAtTime(String EventInput){ | ||
try{ | ||
int indx = EventInput.indexOf("/at"); | ||
String by = EventInput.substring(indx); | ||
String[] array = by.split(" "); | ||
return array[2]; | ||
}catch (Exception e) | ||
{ | ||
return ""; | ||
} | ||
} | ||
|
||
} |
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,10 @@ | ||
|
||
public enum KEYWORD { | ||
TODO, | ||
DEADLINE, | ||
EVENT, | ||
LIST, | ||
DONE, | ||
BYE | ||
} | ||
|
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,35 @@ | ||
import java.util.*; | ||
|
||
public class ListHandler { | ||
|
||
private Vector ListStorage = new Vector(); | ||
|
||
public void addToDo(String body){ | ||
ListStorage.add(new Todo(body)); | ||
} | ||
|
||
public void addDeadline(String body, String by, String time){ | ||
ListStorage.add(new Deadline(body, by, time)); | ||
} | ||
|
||
public void addEvent(String body, String at, String timePeriod){ | ||
ListStorage.add(new Event(body, at, timePeriod)); | ||
} | ||
|
||
public Vector GetList(){ | ||
return ListStorage; | ||
} | ||
|
||
public Task UpdateListItem(String index){ | ||
try { | ||
int idx = Integer.parseInt(index.trim()); | ||
Task task = (Task) ListStorage.get(idx - 1); | ||
task.markAsDone(); | ||
|
||
return task; | ||
|
||
} catch (NumberFormatException e) { } catch (ArrayIndexOutOfBoundsException e) { } | ||
|
||
return null; | ||
} | ||
} |
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.
According to the naming convention, Variable names must be in camelCase.
displayUnit, inputUnit and etc.
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.
Thanks for pointing this out. I missed this while refactoring.