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

[Aaron Chan Zhi] iP #73

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e85afad
Add: Level 0 (Greet)
AaaaaronC Aug 25, 2022
52a99bb
Level 1 (Greet, Echo, Exit)
AaaaaronC Aug 25, 2022
150fe48
Add: Level 1 (Greet, Echo, Exit)
AaaaaronC Aug 25, 2022
331f166
Add: Level 2 (Add, List)
AaaaaronC Aug 25, 2022
fa24764
Add: Level 3 (Mark as done)
AaaaaronC Aug 26, 2022
b8d7ebf
Add: Level 4 (ToDo, Event, Deadline)
AaaaaronC Aug 31, 2022
8226e88
Add: Level 5(Handle Errors)
AaaaaronC Sep 8, 2022
468217a
Remove: unnecessary package
AaaaaronC Sep 8, 2022
57f5e5b
Add: Level 6 (Delete)
AaaaaronC Sep 15, 2022
c84fc42
Add: Level 7 (Save)
AaaaaronC Sep 15, 2022
7878253
Merge: Level-6 and Level-7
AaaaaronC Sep 15, 2022
6f0ba3e
Add: Accounted for adding task with same name
AaaaaronC Sep 27, 2022
ef55e2a
Add: Level 8 (More OOP)
AaaaaronC Sep 28, 2022
0dc6154
Add: More OOP
AaaaaronC Sep 28, 2022
220ffab
Add: Level 9 (Find)
AaaaaronC Sep 28, 2022
7b7655d
Add: branch-Level-9
AaaaaronC Sep 29, 2022
d2d116b
Add: Javadoc comments
AaaaaronC Sep 30, 2022
0d3c5f2
Merge branch 'master' of https://github.com/AaaaaronC/ip
AaaaaronC Sep 30, 2022
a896371
Merge branch 'master' into branch-Level-9
AaaaaronC Sep 30, 2022
535e3d5
Merge pull request #2 from AaaaaronC/branch-Level-9
AaaaaronC Sep 30, 2022
700f8dc
Add: Feature List
AaaaaronC Sep 30, 2022
58d565c
Merge pull request #3 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
6e29fb5
Add: Feature List
AaaaaronC Sep 30, 2022
8b48fe4
Merge pull request #4 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
45f6814
Fix: Feature List new lines
AaaaaronC Sep 30, 2022
4952e2e
Merge pull request #5 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
02a4770
Add: list
AaaaaronC Sep 30, 2022
bb1accf
Merge pull request #6 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
15debf3
Added: all features
AaaaaronC Sep 30, 2022
16e254f
Merge pull request #7 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
afdc14c
Fix: small errors in formatting
AaaaaronC Sep 30, 2022
a2517fd
Merge pull request #8 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
8d80670
Add: intro paragraph
AaaaaronC Sep 30, 2022
64900ab
Merge pull request #9 from AaaaaronC/branch-UG
AaaaaronC Sep 30, 2022
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.
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 {
private String dueDate;

public Deadline(String description, String dueDate){
Copy link

Choose a reason for hiding this comment

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

There should be spacing before braces (applies the whole file)

this.description = description;
this.isDone = false;
this.taskType = "D";
this.dueDate = dueDate;
}

public String getDueDate(){
return this.dueDate;
}
}
Binary file modified src/main/java/Duke.class
Binary file not shown.
78 changes: 67 additions & 11 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class Duke {
public static void main(String[] args) {
boolean isExit = false;
Copy link

Choose a reason for hiding this comment

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

An alternative name can be used for the boolean isExit so that the purpose of the boolean is clearer

Scanner scanner = new Scanner(System.in);
TaskList task_list = new TaskList();
TaskList taskList = new TaskList();

String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
Expand All @@ -23,16 +23,17 @@ public static void main(String[] args) {
//Getting Input
System.out.println("---------------------------------------------------");

Choose a reason for hiding this comment

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

potentially add ---------... as a constant to increase readability of print statements.

System.out.print("You: ");
String raw_input = scanner.nextLine();
String[] input_list = raw_input.split(" ");
String cmd = input_list[0];
String rawInput = scanner.nextLine();
String[] inputList = rawInput.split(" ");
String cmd = inputList[0];
Copy link

Choose a reason for hiding this comment

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

Name of variable can be improve, for example rather than cmd, it can be command

Choose a reason for hiding this comment

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

Consider writing variable names in full to make it more readable

Copy link

Choose a reason for hiding this comment

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

You could consider renaming the variable to "command" so that it is clearer to the reader

String description;

//Responding
switch (cmd) {
Copy link

Choose a reason for hiding this comment

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

The switch statement should be aligned with the case statements.

Copy link

Choose a reason for hiding this comment

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

Can do the printing in another method to make the code look cleaner

Copy link

Choose a reason for hiding this comment

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

Indentation not needed for switch and case statements

case ("list"):

Choose a reason for hiding this comment

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

Avoid magic strings, so maybe for each of these cases, you can say for ex: LIST = "list" and reference the constant in the if statement

System.out.println("---------------------------------------------------");
System.out.println("Tasks: ");
task_list.printList();
taskList.printList();
break;
case ("bye"):
isExit = true;
Expand All @@ -44,16 +45,71 @@ public static void main(String[] args) {
System.out.println("---------------------------------------------------");
System.out.println("Marked as done:");

String task_description = String.join(" ", Arrays.copyOfRange(input_list, 1, input_list.length));
task_list.searchTask(task_description).markAsDone();
description = String.join(" ", Arrays.copyOfRange(inputList, 1, inputList.length));
taskList.searchTask(description).markAsDone();

System.out.print("[X] ");
System.out.println(task_description);
System.out.println(description);
break;
default: //Add to list
case ("unmark"):
System.out.println("---------------------------------------------------");
System.out.println("Added: " + raw_input);
task_list.addTask(raw_input);
System.out.println("Marked as not completed:");

description = String.join(" ", Arrays.copyOfRange(inputList, 1, inputList.length));
taskList.searchTask(description).markAsNotDone();

System.out.print("[ ] ");
System.out.println(description);
break;
case ("todo"): //Add to list
System.out.println("---------------------------------------------------");
description = String.join(" ", Arrays.copyOfRange(inputList, 1, inputList.length));
System.out.println("Added:");
System.out.println(" [T][ ] " + description);
taskList.addToDo(description);
System.out.println("Now you have " + taskList.getSize() + " tasks in the list.");
break;
case ("deadline"):
System.out.println("---------------------------------------------------");
int byPosition = 0;
String dueDate;
for (int i=0; i<inputList.length; i++){
Copy link

Choose a reason for hiding this comment

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

You could consider adding spaces before and after comparison operators to improve readability

if (inputList[i].equals("by")) {
byPosition = i;
break;
}
}
if (byPosition == 0){
System.out.println("Please state the deadline!");

Choose a reason for hiding this comment

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

Good job on adding error handling!

break;
}
description = String.join(" ", Arrays.copyOfRange(inputList, 1, byPosition));
dueDate = String.join(" ", Arrays.copyOfRange(inputList, byPosition+1, inputList.length));
System.out.println("Added:");
System.out.println(" [D][ ] " + description + " (by: " + dueDate + ")");
taskList.addDeadline(description, dueDate);
System.out.println("Now you have " + taskList.getSize() + " tasks in the list.");
break;
case ("event"):
System.out.println("---------------------------------------------------");
int atPosition = 0;
String dateTime;
for (int i=0; i<inputList.length; i++){

Choose a reason for hiding this comment

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

Consider adding spaces in between calculations

if (inputList[i].equals("at")){
atPosition = i;
break;
}
}
if (atPosition == 0){
System.out.println("Please state the date and time!");
break;
}
description = String.join(" ", Arrays.copyOfRange(inputList, 1, atPosition-1));
dateTime = String.join(" ", Arrays.copyOfRange(inputList, atPosition+1, inputList.length));
System.out.println("Added:");
System.out.println(" [E][ ] " + description + " (at: " + dateTime + ")");
taskList.addEvent(description, dateTime);
System.out.println("Now you have " + taskList.getSize() + " tasks in the list.");
break;
}
}
Expand Down
Binary file added src/main/java/Event.class
Binary file not shown.
14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task {
protected String dateTime;

public Event(String description, String dateTime){
this.description = description;
this.isDone = false;
this.taskType = "E";

Choose a reason for hiding this comment

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

make taskType a static final variable and instantiate it not in the constructor

this.dateTime = dateTime;
}

public String getDateTime(){
return this.dateTime;
}
}
Binary file modified src/main/java/Task.class
Binary file not shown.
25 changes: 20 additions & 5 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
public class Task {
public String description;
protected String taskType;
protected boolean isDone;

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

public String getStatusIcon() {
return (isDone ? "X" : " ");
}

public String getTaskType(){
return taskType;
}

public void setTaskType(String type){
taskType = type;
}

public void markAsDone() {
if (isDone==false) this.isDone = true;
Copy link

Choose a reason for hiding this comment

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

Add spaces before and after the logical operator so that it looks better

}

public void markAsNotDone(){
if (isDone==true) this.isDone = false;

Choose a reason for hiding this comment

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

just do:
if (isDone) {
this.isDone = false;
}

}

public String getDueDate(){
return " ";
}
public String getDateTime(){
return " ";
}
}
Binary file modified src/main/java/TaskList.class
Binary file not shown.
51 changes: 43 additions & 8 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
import java.util.ArrayList;

public class TaskList{

public int size = 0;
protected ArrayList<Task> list = new ArrayList<Task>();

public TaskList(){}

public void addTask(String task_name){
Task task = new Task(task_name);
list.add(task);
public void addToDo(String description){
ToDo toDo = new ToDo(description);
list.add(toDo);
this.size++;
}

public void addDeadline(String description, String dueDate){
Deadline deadline = new Deadline(description, dueDate);
list.add(deadline);
this.size++;
}

public void addEvent(String description, String dateTime){
Event event = new Event(description, dateTime);
list.add(event);
this.size++;
}

public Task getTask(int index){
return list.get(index);
return (Task)list.get(index);
}

public void printList(){
for (int i=0; i<size; i++){
Task tempTask = this.getTask(i);
System.out.print((i+1) + ") ");
System.out.print("[" + tempTask.getStatusIcon() + "] ");
System.out.println(tempTask.description);
String taskType = tempTask.getTaskType();
if (taskType == "T"){
Copy link

Choose a reason for hiding this comment

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

All the printing can be done in a method to prevent repetition

Choose a reason for hiding this comment

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

Magic String, maybe set "T" as a constant TASK = "T" so its easier for readers to know that T corresponds to task :)

tempTask = (ToDo)tempTask;
System.out.print((i+1) + ") ");
System.out.print("[" + tempTask.getTaskType() + "]");
System.out.print("[" + tempTask.getStatusIcon() + "] ");
System.out.println(tempTask.description);
} else if (taskType == "D"){
tempTask = (Deadline) tempTask;
System.out.print((i+1) + ") ");
System.out.print("[" + tempTask.getTaskType() + "]");
System.out.print("[" + tempTask.getStatusIcon() + "] ");
System.out.print(tempTask.description);
System.out.println(" (by: " + tempTask.getDueDate() + ")");
} else if (taskType == "E"){
tempTask = (Event) tempTask;
System.out.print((i+1) + ") ");
System.out.print("[" + tempTask.getTaskType() + "]");
System.out.print("[" + tempTask.getStatusIcon() + "] ");
System.out.print(tempTask.description);
System.out.println(" (by: " + tempTask.getDateTime() + ")");
}
}
}

Expand All @@ -32,4 +63,8 @@ public Task searchTask(String task_description){
}
return null;
}

public int getSize(){
return size;
}
}
Binary file added src/main/java/ToDo.class
Binary file not shown.
9 changes: 9 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class ToDo extends Task {

public ToDo(String description){

Choose a reason for hiding this comment

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

Consider adding spaces in between method name and inputs

this.description = description;
this.isDone = false;
this.taskType = "T";
}

}