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

[TJ-Hoo] iP #190

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a1fb5b3
no message
TJ-Hoo Jan 25, 2023
50e9438
Revert "no message"
TJ-Hoo Jan 30, 2023
8f06dc1
no message
TJ-Hoo Jan 30, 2023
15e6f91
Revert "no message"
TJ-Hoo Jan 30, 2023
f19569e
Level 0
TJ-Hoo Jan 30, 2023
aeb3c02
Level 1
TJ-Hoo Jan 31, 2023
8b22744
Level 2
TJ-Hoo Jan 31, 2023
1feb6e5
Level 3
TJ-Hoo Feb 1, 2023
7c31d51
Level 4
TJ-Hoo Feb 1, 2023
1bf5e36
A-CodingStandard
TJ-Hoo Feb 9, 2023
3d6f6e3
A-CodingQuality
TJ-Hoo Feb 9, 2023
875ec03
Level-5
TJ-Hoo Feb 16, 2023
2f9f975
Level-6
TJ-Hoo Feb 22, 2023
6bdd653
Level-7
TJ-Hoo Feb 22, 2023
e1391de
Merge branch 'branch-level-7'
TJ-Hoo Feb 25, 2023
8206b33
Level-9
TJ-Hoo Feb 25, 2023
2e3fd7c
Merge pull request #1 from TJ-Hoo/branch-level-9
TJ-Hoo Feb 25, 2023
4375e13
A-JavaDoc
TJ-Hoo Feb 25, 2023
905f7d0
Merge pull request #2 from TJ-Hoo/branch-JavaDoc
TJ-Hoo Feb 25, 2023
1ebdea6
Update README.md
TJ-Hoo Feb 25, 2023
31322c7
Update README.md
TJ-Hoo Feb 25, 2023
3986655
no message
TJ-Hoo Feb 25, 2023
9c0ba57
Rename README.md to UserGuide
TJ-Hoo Feb 26, 2023
f221b77
Merge remote-tracking branch 'origin/master'
TJ-Hoo Feb 26, 2023
ce6d09e
Merge remote-tracking branch 'origin/master'
TJ-Hoo Feb 26, 2023
c25b455
Update README.md
TJ-Hoo Feb 26, 2023
f8faf8e
Update README.md
TJ-Hoo Feb 26, 2023
9366fd6
Update README.md
TJ-Hoo Feb 26, 2023
4eb7c4a
Minor Fixes
TJ-Hoo Feb 26, 2023
24afabf
Merge remote-tracking branch 'origin/master'
TJ-Hoo Feb 26, 2023
3f092ce
Minor improvements
TJ-Hoo Feb 28, 2023
dc79a03
Minor bug fixes
TJ-Hoo Feb 28, 2023
fd2c8f9
Minor fix
TJ-Hoo Mar 1, 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
11 changes: 11 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Deadline extends Task {
protected String due;

Choose a reason for hiding this comment

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

Use noun for variable. Perhaps dueDate is a better name for it.

public Deadline(String info, String due) {

Choose a reason for hiding this comment

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

Perhaps name is a better naming for the variable instead of info

super(info);
this.due = due;
}
@Override
public String toString(){
return "[D]" + super.toString() + "(by: " + due + ")";
}
}
89 changes: 82 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,85 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.security.InvalidAlgorithmParameterException;
import java.util.MissingFormatArgumentException;
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Hello! I'm Duke \nWhat can I do for you?");
Scanner in = new Scanner(System.in);
ArrayList<Task> tasks = new ArrayList<Task>();

String userInput;
while(in.hasNext()){
userInput = in.nextLine();
if(userInput.equals("bye")){

Choose a reason for hiding this comment

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

Leave a space before the open curly bracket

System.out.println("Bye. Hope to see you again soon!");
break;
} else if(userInput.contains("list")) {
for (int i = 0; i < tasks.size(); i++) {
System.out.print(i + 1 + ".");
System.out.println(tasks.get(i).toString());
}
} else if (userInput.contains("todo")) {
String info = userInput.substring(5).trim();
tasks.add(new Todo(info));
int finalTask = tasks.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(tasks.get(finalTask).toString());
if (tasks.size() == 1) {
System.out.println("Now you have " +tasks.size()+" task in the list.");
} else {
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
}
} else if (userInput.contains("deadline")) {
String [] listArray = userInput.split("/",2);

Choose a reason for hiding this comment

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

Consider changing to a more meaningful name such as phrases

String description = listArray[0];
String dueDate = listArray[1];
String info = description.substring(8).trim();

Choose a reason for hiding this comment

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

Consider avoid all these magic numbers, use named constant instead.
Perhaps use space to split up the phrase instead of hardcoding the character position.

String due = dueDate.substring(3).trim();

Choose a reason for hiding this comment

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

Try to avoid similar/confusing naming of variable

tasks.add(new Deadline(info, due));
int finalTask = tasks.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(tasks.get(finalTask).toString());
if (tasks.size() == 1) {
System.out.println("Now you have " + tasks.size() + " task in the list.");
} else {
System.out.println("Now you have " + tasks.size() + " tasks in the list.");

Choose a reason for hiding this comment

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

Consider creating a method for this since it is used a few times in the code

}
} else if (userInput.contains("event")) {
String [] listArray = userInput.split("/",3);
String description = listArray[0];
String startTime = listArray[1];
String endTime = listArray[2];

Choose a reason for hiding this comment

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

User might not give the desired input. Consider implement some error handling taught in week 5

String info = description.substring(6).trim();
String start = startTime.substring(5).trim();
String end = endTime.substring(3).trim();
tasks.add(new Event(info, start, end));
int finalTask = tasks.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(tasks.get(finalTask).toString());
if (tasks.size() == 1){
System.out.println("Now you have " + tasks.size() + " task in the list.");
} else {
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
}
} else if(userInput.contains("mark")){
Integer itemNumber;

Choose a reason for hiding this comment

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

You can still use normal int data type

String [] commandIndex = userInput.split(" ",2);
itemNumber = Integer.parseInt(IndexArr[1])-1;
if (userInput.equals("unmark")) {
System.out.println("OK, I've marked this task as not done yet:");
tasks.get((int) itemNumber).isCompleted = false;
System.out.println(tasks.get(itemNumber).toString());
}
else {
System.out.println("Nice! I've marked this task as done:");
tasks.get(itemNumber).isCompleted = true;
System.out.println(tasks.get(itemNumber).toString());
}
} else {
tasks.add(new Task(userInput, false));
System.out.println("added: " + userInput);
}
}
}
}
}

Choose a reason for hiding this comment

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

Relatively long and deep nested code. Consider break up the code with more abstractions. (create method for segments that are used repeatedly and a method for each command)

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 {
protected String startTime;
protected String endTime;

public Event(String info, String startTime, String endTime) {
super(info);
this.startTime = startTime;
this.endTime = endTime;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(from: " + startTime + " to: " + endTime + ")";
}
}
14 changes: 14 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Task {
protected String name;
protected boolean isCompleted;
public Task(String info) {
this.name = info;
}
public Task(String info, boolean isCompleted) {
this.name = info;
isCompleted = false;
}
public String toString () {
return(isCompleted?"[X]"+this.name:"[ ]"+this.name);
}
}
8 changes: 8 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Todo extends Task {
public Todo (String info) {
super (info);
}
public String toString() {

Choose a reason for hiding this comment

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

Perhaps adding override annotation to indicate that the method is overriding a method from the parent class. Be consistent in the annotations for all the classes.

return "[T]" + super.toString();
}
}