Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Deadline extends Task{
protected String by;

public Deadline(String description, String by) throws DukeException{
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
94 changes: 88 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,92 @@
import java.util.Scanner;
import java.util.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.

Good job! names representing packages are in lower case

import java.util.ArrayList;
public class Duke {
protected final static String line = "_______________________________________________";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

follow the correct naming standard for constants

private static void print(String message){
System.out.println(line);
System.out.println(message);
System.out.println(line);
}
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String greet = "Hello! I'm Elwin\n" + "What can I do for you?";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can use capital letters for constant eg. GREET

//String line = "_______________________________________________";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove unecessary code

String exit = "Bye. Hope to see you again soon!";

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 this line is used only once, should it be extracted out and just print it directly when needed?

String listRequirements = "Here are the tasks in your 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.

Good job! Use of camelCase

String markRequirements = "Nice! I've marked this task as done:";
String unmarkRequirements = "OK, I've marked this task as not done yet:";
String markFormat = "^mark \\d+$";
String unmarkFormat = "^unmark \\d+$";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I have some confusion regarding these strings. Can you provide some clarification on their meaning?

System.out.println(line);
System.out.println(greet);
System.out.println(line);
Scanner scanner = new Scanner(System.in);
List<Task> todoList = new ArrayList<>();
while(true){
String input = scanner.nextLine();
if(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.

Remember to add spacing for if else class statements eg. if (something) {

break;
}else if(input.equals("list")){
System.out.println(line);
System.out.println(listRequirements);
for(int i = 0; i < todoList.size(); i++){
System.out.println(i+1 + "." + todoList.get(i));
}
System.out.println(line);
}else if(input.matches(markFormat)) {
int index = Integer.parseInt(input.substring(5));
try{
todoList.get(index-1).unmarkAsDone();
}catch(IndexOutOfBoundsException e){
print("☹ OOPS!!! The task number is not in the list.");
continue;
}
print(markRequirements+"\n "+todoList.get(index-1));
}else if(input.matches(unmarkFormat)) {
int index = Integer.parseInt(input.substring(7));
try{
todoList.get(index-1).unmarkAsDone();
}catch(IndexOutOfBoundsException e){
print("☹ OOPS!!! The task number is not in the list.");
continue;
}
print(unmarkRequirements+"\n "+todoList.get(index-1));
}else if(input.split(" ")[0].equals("todo")){
Todo todo;
try{
todo = new Todo(input.substring(4, input.length()));
}catch(DukeException e){
continue;
}
todoList.add(todo);
print("Got it. I've added this task:\n "+todo+"\nNow you have " + todoList.size() + " tasks in the list.");
}else if(input.split(" ")[0].equals("deadline")){
Deadline deadline;
try {
deadline = new Deadline(input.split("/")[0].substring(9, input.split("/")[0].length() - 1), input.split("/")[1].replace("by ", ""));
}catch (DukeException e){
continue;
}
todoList.add(deadline);
print("Got it. I've added this task:\n "+deadline+"\nNow you have " + todoList.size() + " tasks in the list.");
}else if(input.split(" ")[0].equals("event")){
Event event;
try{
event = new Event(input.split("/")[0].substring(5, input.split("/")[0].length()-1), input.split("/")[1], input.split("/")[2]);
}catch(DukeException e){
continue;
}catch(StringIndexOutOfBoundsException e){
print("☹ OOPS!!! The description of a event should use \\ mark start time and end time.");
continue;
}
todoList.add(event);
print("Got it. I've added this task:\n "+event+"\nNow you have " + todoList.size() + " tasks in the list.");
}else{
print("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
scanner.close();
System.out.println(exit);
System.out.println(line);
}
}
9 changes: 9 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class DukeException extends Exception{
protected String line = "_______________________________________________";
public DukeException(String message){
super(message);
System.out.println(line);
System.out.println(message);
System.out.println(line);
}
}
19 changes: 19 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Event extends Task{
protected String by;
protected String from;
public Event(String description, String from, String by) throws DukeException{
super(description);
if(!from.contains("from ")){
throw new DukeException("☹ OOPS!!! The description of a event must contain \"from\" time.");
}else if(!by.contains("to ")){
throw new DukeException("☹ OOPS!!! The description of a event must contain \"to\" time.");
}
this.from = from;
this.by = by;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + this.from + " to: " + this.by + ")";
}
}
29 changes: 29 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Task{
protected String description;
protected boolean isDone;

public Task(String description) throws DukeException {
if(description.isBlank()){
throw new DukeException("☹ OOPS!!! The description of a task cannot be empty.");
}
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public void markAsDone() {
this.isDone = true;
}

public void unmarkAsDone(){
this.isDone = false;
}

@Override
public String toString() {
return "[" + getStatusIcon() + "]" + this.description;
}
}
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) throws DukeException{
super(description);
}

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