-
Notifications
You must be signed in to change notification settings - Fork 200
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
[Yan Zaiya] iP #211
base: master
Are you sure you want to change the base?
[Yan Zaiya] iP #211
Changes from 4 commits
948e367
ed23c92
3443a1a
e45b3f9
266f1af
348e162
7a661ff
cade921
fa052ea
080beee
483db36
33aed0d
4392566
22f3a3f
226cefa
1d2e544
8e79147
4cb3354
0d982de
8e72009
0d0c7ea
20905f4
2940847
8e45cf8
07ecaaa
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,18 @@ | ||
public class Deadline extends Task{ | ||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String getTypeIcon() { | ||
return "[D]"; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return getTypeIcon() + super.getStatusIcon() +super.description + " (by: " + this.by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,75 @@ | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static String DIVIDER_LINE = "______________________________\n"; | ||
|
||
public static void main(String[] args) { | ||
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. Your main method feels a bit long, can consider modularizing it. According to the textbook, the recommendation is to have 30 LOC. |
||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
String greet = DIVIDER_LINE | ||
+ "Hello! I'm Duke\n" | ||
+ "What can i do for you\n" | ||
+ DIVIDER_LINE; | ||
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. Good job combining the welcome statement into one string |
||
System.out.println(greet); | ||
boolean shouldContinue = true; | ||
Scanner in = new Scanner(System.in); | ||
int taskCount = 0; | ||
String action; | ||
Task[] tasks = new Task[100]; | ||
while (shouldContinue) { | ||
action = in.nextLine(); | ||
if (action.equals("bye")) { | ||
System.out.println(DIVIDER_LINE + "Bye. Hope to see you again soon!\n" + DIVIDER_LINE); | ||
shouldContinue = false; | ||
}else if (action.equals("list")) { | ||
System.out.print(DIVIDER_LINE); | ||
for (int i = 0; i < taskCount; i += 1) { | ||
System.out.println(Integer.toString(i + 1) + ". " +tasks[i].toString()); | ||
} | ||
System.out.println(DIVIDER_LINE); | ||
}else if (action.startsWith("mark")){ | ||
int dividerPos = action.indexOf(" "); | ||
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 you could spell out "position" or change it to "Index" |
||
int toBeMarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1; | ||
tasks[toBeMarked].markAsDone(); | ||
System.out.println(DIVIDER_LINE + "Nice! I've marked this task as done:\n" | ||
+ tasks[toBeMarked].toString() + "\n" + DIVIDER_LINE); | ||
}else if (action.startsWith("unmark")) { | ||
int dividerPos = action.indexOf(" "); | ||
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 you could consider writing your variable name in full? |
||
int toBeUnmarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1; | ||
tasks[toBeUnmarked].markAsUndone(); | ||
System.out.println(DIVIDER_LINE + "Nice! I've marked this task as undone:\n" | ||
+ tasks[toBeUnmarked].getStatusIcon() + " " + tasks[toBeUnmarked].description | ||
+ "\n" + DIVIDER_LINE); | ||
}else if (action.startsWith("todo")){ | ||
tasks[taskCount] = new Task(action.substring(5)); | ||
System.out.println(DIVIDER_LINE + "added:\n" + tasks[taskCount].toString() + "\n" + DIVIDER_LINE); | ||
taskCount += 1; | ||
printNumTask(taskCount); | ||
}else if (action.startsWith("deadline")) { | ||
int dividerPosition = action.indexOf("/by"); | ||
tasks[taskCount] = new Deadline(action.substring(9,dividerPosition - 1), | ||
action.substring(dividerPosition + 4)); | ||
System.out.println(DIVIDER_LINE + "added:\n" + tasks[taskCount].toString() + "\n" + DIVIDER_LINE); | ||
taskCount += 1; | ||
printNumTask(taskCount); | ||
}else if (action.startsWith("event")) { | ||
int dividerPosition1 = action.indexOf("/from"); | ||
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. You repeat this line of code quite often. Consider creating a method and passing the respective variable of |
||
int dividerPosition2 = action.indexOf("/to"); | ||
tasks[taskCount] = new Event(action.substring(6,dividerPosition1 - 1), | ||
action.substring(dividerPosition1 + 6, dividerPosition2 - 1), | ||
action.substring(dividerPosition2 + 4)); | ||
System.out.println(DIVIDER_LINE + "added:\n" + tasks[taskCount].toString() + "\n" + DIVIDER_LINE); | ||
taskCount += 1; | ||
printNumTask(taskCount); | ||
} | ||
} | ||
} | ||
|
||
public static void printNumTask(int taskCount) { | ||
System.out.println("Now you have " + taskCount + " tasks in the list"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class Event extends Task{ | ||
protected String from; | ||
protected String to; | ||
|
||
public Event(String description, String from, String to){ | ||
super(description); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
@Override | ||
public String getTypeIcon() { | ||
return "[E]"; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return getTypeIcon() + super.getStatusIcon() + super.description | ||
+ " (from: " + this.from + " to: " + this.to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
} | ||
|
||
public String getTypeIcon() { | ||
return "[T]"; | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void markAsUndone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String toString() { | ||
return getTypeIcon() + getStatusIcon() + 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.
Be consistent with the space around
+