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

[MichelleLiang0116] iP #200

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d2e1652
Level 0
tingyuliang0116 Jan 20, 2023
875214d
Level 0
tingyuliang0116 Jan 20, 2023
546d365
Level-1 Bye
tingyuliang0116 Jan 25, 2023
e5c4d7f
Level-1 Bye
tingyuliang0116 Jan 25, 2023
eaba19d
Level-1 List
tingyuliang0116 Jan 26, 2023
1097c11
Level-3 MarkAsDone
tingyuliang0116 Jan 26, 2023
2c0ac37
A-CodingStandard
tingyuliang0116 Jan 26, 2023
5e67ea1
Level-4
tingyuliang0116 Feb 1, 2023
0a7d6b0
Level-4
tingyuliang0116 Feb 1, 2023
0bd338f
Level-4
tingyuliang0116 Feb 1, 2023
dcbf7d7
Level-4
tingyuliang0116 Feb 1, 2023
fb2bb85
A-CodingStandard
tingyuliang0116 Feb 1, 2023
37ae4e7
A-CodingStandard
tingyuliang0116 Feb 1, 2023
341d75e
Level-4
tingyuliang0116 Feb 2, 2023
98769f2
A-CodingStandard
tingyuliang0116 Feb 2, 2023
166dbe5
A-CodingStandard
tingyuliang0116 Feb 2, 2023
90bb07f
Level-5
tingyuliang0116 Feb 2, 2023
e81c15c
Merge branch 'master' into branch-Level-5
tingyuliang0116 Feb 8, 2023
189960a
A-Exceptions
tingyuliang0116 Feb 10, 2023
53ca173
A-CodingStandard
tingyuliang0116 Feb 10, 2023
113e069
Level-6
tingyuliang0116 Feb 15, 2023
9922c6d
A-Collections
tingyuliang0116 Feb 15, 2023
3ab622a
Level-7
tingyuliang0116 Feb 15, 2023
379a9f8
A-Jar
tingyuliang0116 Feb 15, 2023
89744ec
A-MoreOOP
tingyuliang0116 Mar 1, 2023
aaf4920
Level-9
tingyuliang0116 Mar 2, 2023
8e2ca77
A-JavaDoc
tingyuliang0116 Mar 2, 2023
52f15f5
Merge pull request #2 from MichelleLiang0116/A-JavaDoc
MichelleLiang0116 Mar 2, 2023
892e5de
Level-9 change
tingyuliang0116 Mar 2, 2023
ffc90fd
Level-9 change
tingyuliang0116 Mar 2, 2023
2691a37
A-UserGuide
tingyuliang0116 Mar 2, 2023
aed8f4a
A-UserGuide
tingyuliang0116 Mar 2, 2023
8a238be
Change some function format
tingyuliang0116 Mar 2, 2023
649fcf5
Merge pull request #3 from MichelleLiang0116/A-JavaDoc
MichelleLiang0116 Mar 3, 2023
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 {

Choose a reason for hiding this comment

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

Inheritance to split task types is well done.

protected final String by;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (by:" + by + ")";
}
}
65 changes: 59 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
import java.util.ArrayList;
import java.util.Scanner;
Copy link

Choose a reason for hiding this comment

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

good job in importing classes explicitly


public class Duke {
private final static ArrayList<Task> taskList = new ArrayList<>();

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 lineBreak = "-----------------";
System.out.println(lineBreak + '\n' + "Hello! I'm Duke" + '\n'
+ "What can I do for you?" + '\n' + lineBreak);
String instruction;
while (true) {
Scanner myObj = new Scanner(System.in);
instruction = myObj.nextLine();
if (instruction.equalsIgnoreCase("list")) {
Copy link

Choose a reason for hiding this comment

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

good job in using string.equalsIgnoreCase when comparing strings

System.out.println(lineBreak + '\n'
+ "Here are the tasks in your list:");

Choose a reason for hiding this comment

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

Executing list command can be done on another java file.

for (int i = 0; i < taskList.size(); i++) {
System.out.println(i + 1 + "." + taskList.get(i).toString());
}
System.out.println(lineBreak);
} else if (instruction.equalsIgnoreCase("bye")) {

Choose a reason for hiding this comment

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

Can add comments between each command's execution to improve readability.

System.out.println(lineBreak + '\n'
+ "Bye. Hope to see you again soon!" + '\n' + lineBreak);
break;
} else if (instruction.toLowerCase().contains("mark")) {
String[] split = instruction.split("\\s+");
int toMark = Integer.parseInt(split[1]);
if (split[0].equalsIgnoreCase("mark")) {
taskList.get(toMark - 1).markAsDone();
System.out.println("Nice! I've marked this task as done: ");
} else {
taskList.get(toMark - 1).markAsUnDone();
System.out.println("OK, I've marked this task as not done yet: ");
}
System.out.println(taskList.get(toMark - 1).toString() + '\n' + lineBreak);
} else {
Task t;

Choose a reason for hiding this comment

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

Naming for this variable can be clearer.

if (instruction.toLowerCase().contains("deadline")) {
String description = instruction.substring(instruction.indexOf(' ') + 1, instruction.indexOf('/'));
String ddl = instruction.substring(instruction.indexOf('/') + 1);
String by = ddl.replace("by", "");
t = new Deadline(description, by);
} else if (instruction.toLowerCase().contains("event")) {
String substring = instruction.substring(instruction.indexOf(' ') + 1);
String[] info = substring.split("/");
String from = info[1].replace("from", "");
String to = info[2].replace("to", "");
t = new Event(info[0], from, to);
} else if (instruction.toLowerCase().contains("todo")) {
String description = instruction.substring(instruction.indexOf(' ') + 1);
t = new Todo(description);
} else {
t = new Task(instruction);
}
taskList.add(t);
System.out.println(lineBreak + '\n' + "Got it. I've added this task:");
System.out.println('\t' + t.toString());
System.out.println("Now you have " + taskList.size() + " tasks in the list." + '\n' + lineBreak);
Copy link

Choose a reason for hiding this comment

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

good job in separating your output string to make your code look neat

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

Choose a reason for hiding this comment

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

Good job restricting access to object variables.

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 void markAsDone() {
this.isDone = true;
}

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

@Override
public String toString() {
return "[" + getStatusIcon() + "] " + description;
}
}
11 changes: 11 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Todo extends Task {

public Todo(String description) {
super(description);
}

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