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

[Yan Zaiya] iP #211

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
18 changes: 18 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Deadline extends Task{
protected String by;

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

@Override
public String getTypeIcon() {
return "[D]";
}

@Override
public String toString(){
return getTypeIcon() + super.getStatusIcon() +super.description + " (by: " + this.by + ")";

Choose a reason for hiding this comment

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

Be consistent with the space around +

}
}
65 changes: 65 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,75 @@
import java.util.Scanner;

public class Duke {
public static String DIVIDER_LINE = "______________________________\n";

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 feels a bit long, can consider modularizing it. According to the textbook, the recommendation is to have 30 LOC.

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String greet = DIVIDER_LINE
+ "Hello! I'm Duke\n"
+ "What can i do for you\n"
+ DIVIDER_LINE;
Copy link

Choose a reason for hiding this comment

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

Good job combining the welcome statement into one string

System.out.println(greet);
boolean shouldContinue = true;
Scanner in = new Scanner(System.in);
int taskCount = 0;
String action;
Task[] tasks = new Task[100];
while (shouldContinue) {
action = in.nextLine();
if (action.equals("bye")) {
System.out.println(DIVIDER_LINE + "Bye. Hope to see you again soon!\n" + DIVIDER_LINE);
shouldContinue = false;
}else if (action.equals("list")) {
System.out.print(DIVIDER_LINE);
for (int i = 0; i < taskCount; i += 1) {
System.out.println(Integer.toString(i + 1) + ". " +tasks[i].toString());
}
System.out.println(DIVIDER_LINE);
}else if (action.startsWith("mark")){
int dividerPos = action.indexOf(" ");
Copy link

Choose a reason for hiding this comment

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

Perhaps you could spell out "position" or change it to "Index"

int toBeMarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
tasks[toBeMarked].markAsDone();
System.out.println(DIVIDER_LINE + "Nice! I've marked this task as done:\n"
+ tasks[toBeMarked].toString() + "\n" + DIVIDER_LINE);
}else if (action.startsWith("unmark")) {
int dividerPos = action.indexOf(" ");
Copy link

Choose a reason for hiding this comment

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

Perhaps you could consider writing your variable name in full?

int toBeUnmarked = Integer.parseInt(action.substring(dividerPos + 1)) - 1;
tasks[toBeUnmarked].markAsUndone();
System.out.println(DIVIDER_LINE + "Nice! I've marked this task as undone:\n"
+ tasks[toBeUnmarked].getStatusIcon() + " " + tasks[toBeUnmarked].description
+ "\n" + DIVIDER_LINE);
}else if (action.startsWith("todo")){
tasks[taskCount] = new Task(action.substring(5));
System.out.println(DIVIDER_LINE + "added:\n" + tasks[taskCount].toString() + "\n" + DIVIDER_LINE);
taskCount += 1;
printNumTask(taskCount);
}else if (action.startsWith("deadline")) {
int dividerPosition = action.indexOf("/by");
tasks[taskCount] = new Deadline(action.substring(9,dividerPosition - 1),
action.substring(dividerPosition + 4));
System.out.println(DIVIDER_LINE + "added:\n" + tasks[taskCount].toString() + "\n" + DIVIDER_LINE);
taskCount += 1;
printNumTask(taskCount);
}else if (action.startsWith("event")) {
int dividerPosition1 = action.indexOf("/from");

Choose a reason for hiding this comment

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

You repeat this line of code quite often. Consider creating a method and passing the respective variable of /from or /by

int dividerPosition2 = action.indexOf("/to");
tasks[taskCount] = new Event(action.substring(6,dividerPosition1 - 1),
action.substring(dividerPosition1 + 6, dividerPosition2 - 1),
action.substring(dividerPosition2 + 4));
System.out.println(DIVIDER_LINE + "added:\n" + tasks[taskCount].toString() + "\n" + DIVIDER_LINE);
taskCount += 1;
printNumTask(taskCount);
}
}
}

public static void printNumTask(int taskCount) {
System.out.println("Now you have " + taskCount + " tasks in the list");
}
}
21 changes: 21 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 getTypeIcon() {
return "[E]";
}

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

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

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

public String getTypeIcon() {
return "[T]";
}

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

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

public String toString() {
return getTypeIcon() + getStatusIcon() + description;
}

}