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

[Edward Alvin] ip #305

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
43b3d55
Create an echo() and replyBye() method for Duke
ThePrevailingOne Jan 29, 2022
319056f
Add welcome message for Duke
ThePrevailingOne Jan 29, 2022
0688e25
Implement word list into Duke
ThePrevailingOne Jan 29, 2022
53466c7
Implement marking/unmarking of word list in Duke
ThePrevailingOne Jan 29, 2022
be0072b
Refactor word list into its own class
ThePrevailingOne Jan 29, 2022
e8e1092
Create class Todo, Deadline, and Event
ThePrevailingOne Jan 29, 2022
a4f0552
Refactor code using InputType enum and an InputParser
ThePrevailingOne Jan 30, 2022
b0bfa54
Refactor Duke with processInput() and move sout() statements to WordList
ThePrevailingOne Jan 30, 2022
4dcb935
Hotfix minor bug in InputParser
ThePrevailingOne Jan 30, 2022
888a7b8
Refactor and adjust WordList as well as Duke to adjust with Todo, Dea…
ThePrevailingOne Jan 30, 2022
94995b9
Merge pull request #1 from ThePrevailingOne/skeleton
ThePrevailingOne Jan 30, 2022
28a9832
Add new Exceptions for basic invalid inputs
ThePrevailingOne Jan 30, 2022
5aa3725
Merge pull request #2 from ThePrevailingOne/exception-handling
ThePrevailingOne Jan 30, 2022
14e2a6a
Merge branch 'master' of github.com:ThePrevailingOne/ip
ThePrevailingOne Jan 30, 2022
b307f61
Implement saving system using org.json, Create JSONFileManager, and R…
ThePrevailingOne Feb 7, 2022
082bd2e
Implement date and time with DateTime to replace String
ThePrevailingOne Feb 9, 2022
f451d9f
Merge branch 'datetime'
ThePrevailingOne Feb 9, 2022
1e84453
Add more OOP DukeUI, and edit .gitignore
ThePrevailingOne Feb 9, 2022
d93678d
Merge branch 'a-moreoop'
ThePrevailingOne Feb 9, 2022
0ae6bae
Refactor into packages and fix input whitespaces
ThePrevailingOne Feb 9, 2022
f5ac54f
Merge branch 'a-packages'
ThePrevailingOne Feb 9, 2022
9017932
Add JUnit Testing
ThePrevailingOne Feb 14, 2022
0da00b1
Add Javadoc into the app
ThePrevailingOne Feb 23, 2022
49667e6
Implement a find feature to Duke
ThePrevailingOne Feb 23, 2022
0df53e3
merge to add-gradle-support
ThePrevailingOne Feb 23, 2022
06db74c
Merge branch 'master' into add-gradle-support
ThePrevailingOne Feb 23, 2022
61632f0
Add gradle support
ThePrevailingOne Feb 23, 2022
2c1ab2b
Merge branch 'add-gradle-support'
ThePrevailingOne Feb 23, 2022
de030de
Update gradle to 7.3 and remove save file
ThePrevailingOne Feb 23, 2022
9701571
Add JavaFX to dependencies
ThePrevailingOne Feb 23, 2022
2fb2a5d
Add GUI
ThePrevailingOne Feb 24, 2022
9cbecdf
Merge branch 'JavaFx'
ThePrevailingOne Feb 24, 2022
939b9ab
Hotfix data/ folder and remove unused code
ThePrevailingOne Feb 24, 2022
f2136c3
Allow user to sort the list
ThePrevailingOne Mar 1, 2022
e089191
Hotfix souts
ThePrevailingOne Mar 1, 2022
6d1fe81
Add a user guide
ThePrevailingOne Mar 1, 2022
19b492b
Set theme jekyll-theme-cayman
ThePrevailingOne Mar 1, 2022
559e67e
Set theme jekyll-theme-slate
ThePrevailingOne Mar 1, 2022
3080ed8
Set theme jekyll-theme-cayman
ThePrevailingOne Mar 1, 2022
941e353
Change user guide title
ThePrevailingOne Mar 1, 2022
020089e
Merge branch 'master' of github.com:ThePrevailingOne/ip
ThePrevailingOne Mar 1, 2022
705a92d
Change gradle version
ThePrevailingOne Mar 19, 2022
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
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends WordListItem{
static private final String SYMBOL = "[D]";
private String datetime;

public Deadline(String description, String datetime) {
super(description);
this.datetime = datetime;
}

@Override
public String toString() {
return SYMBOL + super.toString() + "(by: " + this.datetime + ")";
}
}
58 changes: 58 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
import java.util.Scanner;

public class Duke {
static WordList wordList;

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
wordList = new WordList();

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

replyWelcomeMessage();
String input;
while (true) {
input = sc.nextLine();
if (input.isEmpty()) {
warnEmpty();
continue;
}

Object[] parseResult = InputParser.parseInput(input);
InputType inputType = (InputType) parseResult[0];
String value = (String) parseResult[1];

processInput(inputType, value);
if (inputType == InputType.BYE) {
break;
}
}
}

public static void processInput(InputType inputType, String value) {
switch(inputType) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style-related thing, but there should be a space before the bracket i.e switch (inputType)

case LIST:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the codestyle, there should be no intentation for 'case' clauses in the switch block.

wordList.printList();
break;
case MARK:
wordList.markItem(Integer.parseInt(value));
break;
case UNMARK:
wordList.unmarkItem(Integer.parseInt(value));
break;
case BYE:
replyBye();
break;
case NONE:
wordList.storeWord(value);
break;
}
}

public static void replyWelcomeMessage() {
System.out.println("Hello! I'm Duke");
System.out.println("What can I do for you?");
}

public static void warnEmpty() {
System.out.println("input is Empty!");
}
public static void replyBye() {
System.out.println("Bye. Hope to see you again soon!");
}
}
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends WordListItem{
static private final String SYMBOL = "[E]";
private String datetime;

public Event(String description, String datetime) {
super(description);
this.datetime = datetime;
}

@Override
public String toString() {
return SYMBOL + super.toString() + "(at: " + this.datetime + ")";
}
}
14 changes: 14 additions & 0 deletions src/main/java/InputParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class InputParser {
static Object[] parseInput(String input) {
InputType type = InputType.NONE;
String value = input;
for(InputType inputType: InputType.values()) {
if (input.startsWith(inputType.label)) {
value = input.substring(inputType.label.length() + 1);
type = inputType;
return new Object[]{type, value};
}
}
return new Object[]{type, value};
}
}
14 changes: 14 additions & 0 deletions src/main/java/InputType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public enum InputType {
BYE("bye"),
LIST("list"),
MARK("mark"),
UNMARK("unmark"),
NONE("none");

public final String label;

private InputType(String label) {
this.label = label;
}

}
12 changes: 12 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Todo extends WordListItem{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be a space between WordListItem and {.

static private final String SYMBOL = "[T]";

public Todo(String description) {
super(description);
}

@Override
public String toString() {
return SYMBOL + super.toString();
}
}
49 changes: 49 additions & 0 deletions src/main/java/WordList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import java.util.ArrayList;

public class WordList {
private ArrayList<WordListItem> wordList;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could be renamed to words or something similar to be plural?


public WordList() {
this.wordList = new ArrayList<>();
}

public void storeWord(String word) {
this.wordList.add(new WordListItem(word));
System.out.println(" ------------------------------------");
System.out.println(" added: " + word);
System.out.println(" ------------------------------------");
}

public void markItem(int itemNumber) {
this.wordList.get(itemNumber - 1).markItem();
System.out.println("Nice! I've marked this task as done: ");
System.out.println(" " + this.wordList.get(itemNumber - 1));
}

public void unmarkItem(int itemNumber) {
this.wordList.get(itemNumber - 1).unmarkItem();
System.out.println("Nice! I've marked this task as not done: ");
System.out.println(" " + this.wordList.get(itemNumber - 1));
}

public void printList() {
System.out.println(this);
}

public int length() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coding standards suggest that method names be verbs. Perhaps this could be changed to getLength or something like that.

return this.wordList.size();
}

@Override
public String toString() {
int i = 1;
String str = "";
str += "------------------------------------\n";
for(WordListItem wordListItem: this.wordList) {
str += i + ". " + wordListItem + "\n";
i++;
}
str += "------------------------------------\n";
return str;
}
}
23 changes: 23 additions & 0 deletions src/main/java/WordListItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class WordListItem {
private String description;
private boolean isDone;

public WordListItem(String description) {
this.description = description;
this.isDone = false;
}

public void markItem() {
this.isDone = true;
}

public void unmarkItem() {
this.isDone = false;
}

@Override
public String toString() {
String doneSymbol = isDone ? "[X]" : "[ ]";
return doneSymbol + " " + this.description;
}
}