-
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
[Sebastian Soewanto] iP #205
base: master
Are you sure you want to change the base?
Changes from 5 commits
12a4d6f
3c57457
a96a8be
57d0c6a
bd71f69
7473a4c
fa25e2d
3230034
bb5533e
6fa95ff
ca05154
b07c63e
f44576f
e5fb6f9
47689bc
805e73b
97208ba
a839b28
ca10bdd
62dee31
98a859b
eed248b
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,12 @@ | ||
public class Deadline extends Task { | ||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + "(by: " + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,64 @@ | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
||
String line = "____________________________________________________\n"; | ||
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. Naming can be changed to avoid confusion down the code block, could change to -> e.g. 'static final String margin' (since its a repeating string pattern to be printed out) 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. Constant should be named by CAPITAL LETTER for example String DIVIDER, String LOGO |
||
System.out.println("Hello from\n" + logo); | ||
System.out.print(line + "Hello! I'm Duke\n" + "What can I do for you?\n" + line); | ||
Task[] task = new Task[100]; | ||
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. since the number of task can be more than 100. you can consider to use the dynamic size array 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. task should be renamed to tasks (with s) |
||
int taskCount = 0; | ||
int errorCount = 0; | ||
while(true) { | ||
Scanner userInput = new Scanner(System.in); | ||
String input = userInput.nextLine(); | ||
if (input.equals("bye")) { | ||
System.out.print(line + "Bye. Hope to see you again soon!\n" + line); | ||
break; | ||
} else if (input.startsWith("mark")) { | ||
int mark = Integer.parseInt(input.substring(5)); | ||
task[mark - 1].markDone(); | ||
System.out.print(line); | ||
} else if (input.startsWith("unmark")) { | ||
int unmark = Integer.parseInt(input.substring(7)); | ||
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 naming of ' unmark' is a bit confusing, maybe switch to ' taskToUnmark '? |
||
task[unmark - 1].umarkDone(); | ||
System.out.print(line); | ||
} else if (input.equals("list")) { | ||
System.out.print(line + "Here are the tasks in your list:\n"); | ||
for (int i = 0; i < taskCount; i++) { | ||
System.out.println(i + 1 + "." + task[i]); | ||
} | ||
System.out.print(line); | ||
} else if (input.startsWith("todo")) { | ||
task[taskCount] = new Todo(input.substring(5)); | ||
taskCount++; | ||
System.out.println(line + "Got it. I've added this task:\n" + task[taskCount - 1]); | ||
System.out.print("Now you have " + taskCount + " tasks in the list.\n" + line); | ||
} else if (input.startsWith("deadline")) { | ||
int byIndex = input.indexOf("/by"); | ||
task[taskCount] = new Deadline(input.substring(9, byIndex), input.substring(byIndex + 4)); | ||
taskCount++; | ||
System.out.println(line + "Got it. I've added this task:\n" + task[taskCount - 1]); | ||
System.out.print("Now you have " + taskCount + " tasks in the list.\n" + line); | ||
} else if (input.startsWith("event")) { | ||
int fromIndex = input.indexOf("/from"); | ||
int toIndex = input.indexOf("/to"); | ||
task[taskCount] = new Event(input.substring(6, fromIndex), input.substring(fromIndex + 6, toIndex), input.substring(toIndex + 4)); | ||
taskCount++; | ||
System.out.println(line + "Got it. I've added this task:\n" + task[taskCount - 1]); | ||
System.out.print("Now you have " + taskCount + " tasks in the list.\n" + line); | ||
} else if (errorCount == 10) { | ||
System.out.print(line +"Maybe you can try in another language. Goodbye!\n" + line); | ||
break; | ||
} else { | ||
System.out.print(line + "Sorry, could you please repeat what you just said\n" + line); | ||
errorCount++; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 toString() { | ||
return "[E]" + super.toString() + "(from: " + from + "to: " + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.isDone = false; | ||
this.description = description; | ||
} | ||
|
||
public void markDone() { | ||
isDone = true; | ||
System.out.println("Nice! I've marked this task as done:\n" + this); | ||
} | ||
|
||
public void umarkDone() { | ||
isDone = false; | ||
System.out.println("OK, I've marked this task as not done yet:\n" + this); | ||
} | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String status(){ | ||
if(isDone) { | ||
return "X"; | ||
} | ||
else { | ||
return " "; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + status() + "]" + getDescription(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Todo extends Task { | ||
|
||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
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.
Seems like it is a constant, so maybe consider using
static final LINE_DIVIDER
(or some other similar name)?