-
Notifications
You must be signed in to change notification settings - Fork 270
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
base: master
Are you sure you want to change the base?
[Edward Alvin] ip #305
Changes from 8 commits
d839859
43b3d55
319056f
0688e25
53466c7
be0072b
e8e1092
a4f0552
b0bfa54
4dcb935
888a7b8
94995b9
28a9832
5aa3725
14e2a6a
b307f61
082bd2e
f451d9f
1e84453
d93678d
0ae6bae
f5ac54f
9017932
0da00b1
49667e6
0df53e3
06db74c
61632f0
2c1ab2b
de030de
9701571
2fb2a5d
9cbecdf
939b9ab
f2136c3
e089191
6d1fe81
19b492b
559e67e
3080ed8
941e353
020089e
705a92d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 + ")"; | ||
} | ||
} |
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) { | ||
case LIST: | ||
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. 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!"); | ||
} | ||
} |
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 + ")"; | ||
} | ||
} |
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}; | ||
} | ||
} |
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; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Todo extends WordListItem{ | ||
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. 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(); | ||
} | ||
} |
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; | ||
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. 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() { | ||
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. 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; | ||
} | ||
} |
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; | ||
} | ||
} |
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.
Minor style-related thing, but there should be a space before the bracket i.e
switch (inputType)