Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
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.toString() + " (by: " + by + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task{
String from;
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 + ")";
}
}
18 changes: 18 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Task {
private final String description;
private boolean isCompleted;

public Task(String description) {
this.description = description;
this.isCompleted = false;
}

public void setCompleted(boolean completed) {
isCompleted = completed;
}

@Override
public String toString() {
return isCompleted? "[X] " + description : "[ ]" + description;
}
}
113 changes: 113 additions & 0 deletions src/main/java/Taylor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import java.util.*;

public class Taylor {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't do deep nesting, which is good code quality

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

final String line = "____________________________________________________________";
System.out.println(line);
System.out.println("Hello! I'm Taylor");
System.out.println("What can I do for you?");
System.out.println(line);

String input = sc.nextLine();
List<Task> tasks = new ArrayList<>();
while(!input.equals("bye")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all the printing of the statements, maybe can put it in a method each. For instance, printTodoAdded() and the statement that the todo task have been added will be printed

if(input.equals("list")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use a switch-case instead of if-else?

System.out.println(line);
System.out.println("Here are the tasks in your list:");
for(int i = 0; i < tasks.size(); i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since tasks.size() is repeated used in all of the loops, perhaps can create a variable to store this value

System.out.println(i+1 + "." + tasks.get(i));
}
System.out.println(line);
input = sc.nextLine();
continue;
}

if(input.startsWith("mark")){
String[] words = input.split(" ");
int index = Integer.parseInt(words[1])-1;
if(index<0 || index>=tasks.size()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps can place the code for checking in a method to allow easier reading

System.out.println(line);
System.out.println("Invalid index");
System.out.println(line);
} else {
tasks.get(index).setCompleted(true);
System.out.println("Nice! I've marked this task as done:");
System.out.println(tasks.get(index));
System.out.println(line);
}
input = sc.nextLine();
continue;
}

if(input.startsWith("unmark")){
String[] words = input.split(" ");
int index = Integer.parseInt(words[1])-1;
if(index<0 || index>=tasks.size()) {
System.out.println(line);
System.out.println("Invalid index");
} else {
tasks.get(index).setCompleted(false);
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(tasks.get(index));
System.out.println(line);
}
input = sc.nextLine();
continue;
}

if(input.startsWith("todo")){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear input handling for all the multiple types of commands (list, mark, unmark, todo, event, deadline)

Todo todo = new Todo(input.substring(4));
// tasks.add(todo);
System.out.println(line);
System.out.println("Got it. I've added this task:");
System.out.println(" " + todo);
System.out.println("Now you have "+ tasks.size() +" tasks in the lists");
System.out.println(line);
input = sc.nextLine();
continue;
}

if(input.startsWith("event")){
int from = input.indexOf("/from");
int to = input.indexOf("/to");
String description = input.substring(6,from);
String _from = input.substring(from+6,to);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably used another name instead of _from or _to as it is similar as from and to, which can be confusing

String _to = input.substring(to+4);
Event event = new Event(description,_from,_to);
tasks.add(event);
System.out.println(line);
System.out.println("Got it. I've added this task:");
System.out.println(" " + event);
System.out.println("Now you have "+ tasks.size() +" tasks in the lists");
System.out.println(line);
input = sc.nextLine();
continue;
}

if(input.startsWith("deadline")){
int by = input.indexOf("/by");
String description = input.substring(9,by);
String _by = input.substring(by+4);
Task task = new Deadline(description,_by);
tasks.add(task);
System.out.println(line);
System.out.println("Got it. I've added this task:");
System.out.println(" " + task);
System.out.println("Now you have "+ tasks.size() +" tasks in the lists");
System.out.println(line);
input = sc.nextLine();
continue;
}

System.out.println(line);
System.out.println("added: " + input);
System.out.println(line);
input = sc.nextLine();
}
System.out.println(line);
System.out.println("Bye. Hope to see you again soon!");
System.out.println(line);
}
}
5 changes: 5 additions & 0 deletions src/main/java/TaylorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class TaylorException extends RuntimeException {
public TaylorException(String message) {
super(message);
}
}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}