Skip to content

Commit

Permalink
Level-4: ToDo, Event, Deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Jan 21, 2020
1 parent 29c6129 commit 579fe7b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadlines extends Task{
protected String by;

public Deadlines(String description, String by) {
super(description);
this.by = by;
System.out.println(this);
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by:" + by + ")";
}
}
31 changes: 21 additions & 10 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,32 @@ public static void main(String[] args) {

while(isListening) {
String command = input.nextLine();
String[] command_broken = command.split(" ",2);

if (command.equalsIgnoreCase("bye")) {
System.out.println("Bye. Hope to see you again soon!");
String action = command_broken[0];

if (action.equalsIgnoreCase("bye")) {
System.out.println("Bye. Hope to see you again!");
isListening = false;
} else if (command.equalsIgnoreCase("list")) {

} else if (action.equalsIgnoreCase("list")) {
tasks.printInputs();
} else if (command.length()>3
&& command.substring(0,4).equalsIgnoreCase("done")) {
String s[] = command.split(" ");
int taskNo = Integer.parseInt(s[1]);

} else if (action.equalsIgnoreCase("done")) {
String context = command_broken[1];
int taskNo = Integer.parseInt(context);
tasks.markDone(taskNo);

} else {
System.out.println(command);
tasks.addInput(new Task(command));
} else if (action.equalsIgnoreCase(("deadline"))){
String context = command_broken[1];
String[] context_broken = context.split("/by",2);
tasks.addInput(new Deadlines(context_broken[0], context_broken[1]));
} else if (action.equalsIgnoreCase(("todo"))){
tasks.addInput(new ToDos(command_broken[1]));
} else if (action.equalsIgnoreCase(("event"))){
String context = command_broken[1];
String[] context_broken = context.split("/at",2);
tasks.addInput(new Events(context_broken[0], context_broken[1]));
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Events extends Task{
protected String by;

public Events(String description, String by) {
super(description);
this.by = by;
System.out.println(this);
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at:" + by + ")";
}
}
1 change: 1 addition & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ public class Task {
protected boolean isDone;

public Task(String description) {
System.out.println("Got it, I've added this task");
this.description = description;
this.isDone = false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/ToDos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class ToDos extends Task {

public ToDos(String description) {
super(description);
System.out.println(this);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
5 changes: 3 additions & 2 deletions src/main/java/UserText.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ public UserText() {
userInput = new ArrayList<>();
}

public List<Task> addInput(Task s) {
public void addInput(Task s) {
this.userInput.add(s);
return this.userInput;
System.out.println("Now you have " + userInput.size() + " tasks in the list.");
}

public void printInputs() {
int count = 1;
System.out.println("Here is your list");
for (Task s : userInput) {
System.out.println(count + ". " + s);
count++;
Expand Down

0 comments on commit 579fe7b

Please sign in to comment.