-
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
[Ong Jun Lin Jeremiah] iP #212
base: master
Are you sure you want to change the base?
Changes from 7 commits
2347e0a
5697dca
9d838d8
39997c3
9aab82a
b88f2ef
f5c800f
c88df2a
bd2b27f
fcc0a61
502d1bc
8ba6193
2ad344e
6fe26de
8963781
107d97f
d5071ac
0aa293f
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 Task { | ||
|
||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.getStatusIcon() + super.getDescription() + "(" + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,90 @@ | ||||||||
public class Duke { | ||||||||
import java.util.Scanner; | ||||||||
import java.util.ArrayList; | ||||||||
|
||||||||
public class | ||||||||
Duke { | ||||||||
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. Please bring
Suggested change
|
||||||||
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 is far too long, the recommendation according to the textbook is 30 LOC. Please try to modularize your main method. |
||||||||
String logo = " ____ _ \n" | ||||||||
+ "| _ \\ _ _| | _____ \n" | ||||||||
+ "| | | | | | | |/ / _ \\\n" | ||||||||
+ "| |_| | |_| | < __/\n" | ||||||||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||||||||
System.out.println("Hello from\n" + logo); | ||||||||
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. Can be refactored into print logo function, or you can combine it with the print greeting function |
||||||||
|
||||||||
String line = "____________________________________________________________\n"; | ||||||||
|
||||||||
String greeting = (line + "Hello! I'm Duke\n" + "What can I do for you?\n" + line); | ||||||||
|
||||||||
String goodBye = (line + "Bye. Hope to see you again soon!\n" + line); | ||||||||
|
||||||||
System.out.println(greeting); | ||||||||
Scanner myObj = new Scanner(System.in); | ||||||||
String userInput; | ||||||||
String userInputParts[]; | ||||||||
userInput = myObj.nextLine(); | ||||||||
ArrayList<Task> taskList = new ArrayList<Task>(100); | ||||||||
|
||||||||
while (!userInput.equals("bye")) { | ||||||||
if (userInput.equals("list")) { | ||||||||
System.out.println("Here are the tasks in your list:\n"); | ||||||||
for (Task item : taskList) { | ||||||||
System.out.print((taskList.indexOf(item) + 1) + "."); | ||||||||
System.out.println(item.toString()); | ||||||||
} | ||||||||
System.out.println(line); | ||||||||
} | ||||||||
|
||||||||
//For marking and unmarking items in the list | ||||||||
else if(userInput.contains("mark")) { | ||||||||
int itemNumber = Integer.parseInt(userInput.replaceAll("[^0-9]", "")) - 1; | ||||||||
if (userInput.contains("unmark")) { | ||||||||
taskList.get(itemNumber).markAsUnDone(); | ||||||||
System.out.println("OK, I've marked this task as not done yet:\n" + " " | ||||||||
+ taskList.get(itemNumber).getStatusIcon() + taskList.get(itemNumber).getDescription()); | ||||||||
System.out.println(line); | ||||||||
} else { | ||||||||
taskList.get(itemNumber).markAsDone(); | ||||||||
System.out.println("Nice! I've marked this task as done:\n" + taskList.get(itemNumber).getStatusIcon() + taskList.get(itemNumber).getDescription()); | ||||||||
System.out.println(line); | ||||||||
} | ||||||||
} else if (userInput.contains("event")){ | ||||||||
userInput = userInput.replace("event",""); | ||||||||
userInputParts = userInput.split("/"); | ||||||||
Event event = new Event(userInputParts[0], userInputParts[1], userInputParts[2]); | ||||||||
taskList.add(event); | ||||||||
System.out.println("Got it. I've added this task: "); | ||||||||
System.out.println("[E][ ] " + event.description + "(" + event.from + event.to + ")"); | ||||||||
System.out.println("Now you have " + taskList.size() + " tasks in the list. "); | ||||||||
System.out.println(line); | ||||||||
} else if (userInput.contains("deadline")) { | ||||||||
userInput = userInput.replace("deadline",""); | ||||||||
userInputParts = userInput.split("/"); | ||||||||
Deadline deadline = new Deadline(userInputParts[0], userInputParts[1]); | ||||||||
taskList.add(deadline); | ||||||||
System.out.println("[D][ ] " + deadline.description + "(" + userInputParts[1] + ")"); | ||||||||
System.out.println("Now you have " + taskList.size() + " tasks in the list. "); | ||||||||
System.out.println(line); | ||||||||
} else if (userInput.contains("todo")){ | ||||||||
userInput = userInput.replace("todo",""); | ||||||||
userInput = userInput.replace(" ", ""); | ||||||||
if (userInput.isEmpty()){ | ||||||||
System.out.println("Please do not leave the description empty!"); | ||||||||
System.out.println(line); | ||||||||
continue; | ||||||||
} | ||||||||
Task task = new Task(userInput); | ||||||||
taskList.add(task); | ||||||||
System.out.println("Got it. I've added this task: "); | ||||||||
System.out.println("[T][ ] " + task.description); | ||||||||
System.out.println("Now you have " + taskList.size() + " tasks in the list. "); | ||||||||
System.out.println(line); | ||||||||
} else { | ||||||||
System.out.println("Please enter a valid command!"); | ||||||||
System.out.println(line); | ||||||||
} | ||||||||
|
||||||||
userInput = myObj.nextLine(); | ||||||||
} | ||||||||
System.out.println(goodBye); | ||||||||
} | ||||||||
} | ||||||||
} |
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.getStatusIcon() + super.getDescription() + "(" + from + to + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public void markAsDone() { | ||
|
||
this.isDone = true; | ||
} | ||
|
||
public void markAsUnDone() | ||
{ | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return "[T]" + this.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.