Skip to content
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

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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.getStatusIcon() + super.getDescription() + "(" + by + ")";
}
}
84 changes: 82 additions & 2 deletions src/main/java/Duke.java
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 {

Choose a reason for hiding this comment

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

Suggested change
public class
Duke {
public class Duke {

Copy link

@R-Ramana R-Ramana Feb 11, 2023

Choose a reason for hiding this comment

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

Please bring Duke { in line 5 to the same line as public class (line 4)

Suggested change
public class
Duke {
public class Duke {

public static void main(String[] args) {

Choose a reason for hiding this comment

The 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);
Copy link

Choose a reason for hiding this comment

The 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);
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/Event.java
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 + ")";
}

}
34 changes: 34 additions & 0 deletions src/main/java/Task.java
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;
}
}