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

[Tze Loong] iP #213

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7558b46
Level 0 Greet
TzeLoong Feb 1, 2023
dbc5dac
Level 1. Greet, Echo, Exit
TzeLoong Feb 1, 2023
f808559
Level 2. Add, List
TzeLoong Feb 1, 2023
50aad95
Level-3
TzeLoong Feb 2, 2023
312117e
Update Tasks.java
TzeLoong Feb 2, 2023
98bc638
Coding Standard
TzeLoong Feb 2, 2023
2306a2a
Level-4
TzeLoong Feb 9, 2023
cb74c50
Level-4
TzeLoong Feb 16, 2023
fe13d52
Level-4
TzeLoong Feb 17, 2023
f5259c3
Create Duke.jar
TzeLoong Feb 17, 2023
dc3b488
Delete Duke.jar
TzeLoong Feb 17, 2023
7b1e715
Handle errors
TzeLoong Feb 18, 2023
88c2683
Use of ArrayList<Task>
TzeLoong Feb 18, 2023
1712749
Delete
TzeLoong Feb 18, 2023
de06295
Save
TzeLoong Feb 27, 2023
3b1d6d4
Save
TzeLoong Feb 27, 2023
409496b
Level-7
TzeLoong Feb 27, 2023
8c09680
Level-7
TzeLoong Feb 28, 2023
d44a21d
Level-9
TzeLoong Feb 28, 2023
1e53d33
Added comments
TzeLoong Feb 28, 2023
2b06b30
Added JavaDoc comments
TzeLoong Feb 28, 2023
9a1c515
Merge pull request #1 from TzeLoong/A-JavaDoc
TzeLoong Feb 28, 2023
57076f4
Changes
TzeLoong Mar 1, 2023
b847776
Changes
TzeLoong Mar 1, 2023
c8ce553
Changes
TzeLoong Mar 1, 2023
6df5295
Changes
TzeLoong Mar 2, 2023
212cf99
Updated userguide
TzeLoong Mar 3, 2023
7e9c93f
Update Tasklist.java
TzeLoong Mar 3, 2023
b624d2a
Merge branch 'master' of https://github.com/TzeLoong/ip
TzeLoong Mar 3, 2023
6009396
Added comments
TzeLoong Mar 3, 2023
da04bb5
Create ip.jar
TzeLoong Mar 3, 2023
c7ddfbe
Improvements for v2-updated
TzeLoong Mar 19, 2023
1ad8a59
Improvements for v0.2-updated
TzeLoong Mar 19, 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
Binary file added src/main/java/Deadline.class
Binary file not shown.
15 changes: 15 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Deadline extends Tasks {

protected String by;

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

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

}
Binary file added src/main/java/Duke.class
Binary file not shown.
102 changes: 99 additions & 3 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,106 @@
import java.util.Scanner;

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.

Consistent 4 spaces indent throughout the code, good job


private static Tasks[] list_of_tasks = new Tasks[101];

Choose a reason for hiding this comment

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

Consider other data structures, apart from a fixed size array, to make your product more scalable, especially since we are already approaching recess week :)

private static int counter = 0;

public static void greet_user() {
System.out.println("Hello! I'm Duke \n");
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println(logo);
System.out.println("How can i help u? \n");
}

public static void print_action() {
System.out.println("\n");
System.out.println("I have added this task: ");
System.out.println(list_of_tasks[counter - 1].toString());

System.out.println("You now have " + counter + " tasks in the list.");
}

public static void Todo(String description) {
Tasks t = new ToDo(description);
list_of_tasks[counter] = t;
counter++;
print_action();
}

public static void Deadline(String description, String by) {
Deadline d = new Deadline(description, by);
list_of_tasks[counter] = d;
counter++;
print_action();
}

public static void Event(String description, String start, String end) {

Choose a reason for hiding this comment

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

Avoid using constructor names of other classes as method name. It can be confusing and potential source of bug. Also, consider separate classes for adding new tasks.

Event E = new Event(description, start, end);
list_of_tasks[counter] = E;
counter++;
print_action();
}

public static void List() {
System.out.println("Here are all of your " + counter + " tasks: ");
for (int i = 0; i < counter; i++) {
System.out.println(i + 1 + "." + list_of_tasks[i].toString());
}
}

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.

Try keeping your main method short and have a parser to deal with interpreting user commands instead

greet_user();

Scanner scan = new Scanner(System.in);
String input = scan.nextLine();
String[] command = input.split(" ", 2);

while (!"bye".equals(input)) {
switch (command[0]) {
case "todo":

Choose a reason for hiding this comment

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

Switch-case should not have different indentations.

Todo(command[1]);
break;
case "deadline":
String[] d = command[1].split("/by", 2);
String d_description = d[0];
String d_by = d[1];
Deadline(d_description, d_by);
break;
case "event":

Choose a reason for hiding this comment

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

Perhaps consider using constants instead of strings, for example, COMMAND_EVENT instead of "event"

String[] e = command[1].split("/", 3);
String e_description = e[0];
String e_start = e[1];
String e_end = e[2];
Event(e_description, e_start, e_end);
break;
case "list":
List();
break;
case "mark":
Integer m_index = Integer.valueOf(command[1]);

Choose a reason for hiding this comment

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

m_index, u_index etc. might be easy for the original developer to understand but not for someone else reading it or another person taking over. Consider using clearer naming in this case.

list_of_tasks[m_index - 1].markAsDone();
System.out.println("Nice! This task is completed");
System.out.println(list_of_tasks[m_index - 1].toString());
break;
case "unmark":
Integer u_index = Integer.valueOf(command[1]);
list_of_tasks[u_index - 1].markAsUnDone();
System.out.println("Nice! This task is completed");
System.out.println(list_of_tasks[u_index - 1].toString());
break;
default:
System.out.println("There was an error. Please try again");
break;
}
input = scan.nextLine();
command = input.split(" ", 2);
}
System.out.println("Goodbye. Hope to see u again :) \n");
scan.close();
}
}

}
Binary file added src/main/java/Event.class
Binary file not shown.
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 Tasks {
protected String start;
protected String end;

public Event(String description, String start, String end) {
super(description);
this.start = start;
this.end = end;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(" + start + end + ")";
}
}
Binary file added src/main/java/Tasks.class
Binary file not shown.
28 changes: 28 additions & 0 deletions src/main/java/Tasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public class Tasks {

Choose a reason for hiding this comment

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

Perhaps you could name this class as "Task" (singular) instead as it refers to one task


protected String description;
protected boolean isDone;

public Tasks(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;
}

}
Binary file added src/main/java/ToDo.class
Binary file not shown.
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 Tasks {

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

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