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

[LimHongYao] iP #201

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a63c9f7
Level-0
LimHongYao Jan 17, 2023
ef8d231
Added echo
LimHongYao Jan 27, 2023
bdd7c9d
Added list functionality
LimHongYao Jan 27, 2023
9d94709
Added ability to mark and unmark as done
LimHongYao Jan 31, 2023
a3a4347
Added deadline, event, todo types for list objects
LimHongYao Feb 9, 2023
c711aeb
fixed coding standard issues
LimHongYao Feb 9, 2023
28406be
added bad input handling
LimHongYao Feb 10, 2023
c2a4627
Merge branch 'branch-Level-5'
LimHongYao Feb 10, 2023
6cf1e94
added delete functionality to list
LimHongYao Feb 24, 2023
e3a2df5
added tasklist export functionality
LimHongYao Feb 26, 2023
e0bf091
reverted desktop export path to relative /out path
LimHongYao Feb 28, 2023
e3091cd
Merge branch 'branch-Level-6'
LimHongYao Feb 28, 2023
896ad76
Merge branch 'branch-Level-7'
LimHongYao Feb 28, 2023
44155f7
packaged files
LimHongYao Feb 28, 2023
95409e7
moved some methods to Ui class
LimHongYao Feb 28, 2023
fd05d8e
rewrote and combined mark/unmark methos
LimHongYao Mar 1, 2023
6e7bbe3
reworked and combined mark method
LimHongYao Mar 1, 2023
bc51fbb
Moved switch cases into OOP
LimHongYao Mar 2, 2023
81192bc
added search functionality
LimHongYao Mar 3, 2023
0021e8a
Merge pull request #1 from LimHongYao/branch-Level-9
LimHongYao Mar 3, 2023
4984f8c
added parser class
LimHongYao Mar 3, 2023
61ec054
Merge pull request #2 from LimHongYao/branch-Level-9
LimHongYao Mar 3, 2023
39fb97b
added load from text file functionality
LimHongYao Mar 3, 2023
30d3513
Added javadoc documentation
LimHongYao Mar 3, 2023
86c9546
added javadoc documentation
LimHongYao Mar 3, 2023
0200dab
Merge pull request #3 from LimHongYao/branch-A-JavaDoc
LimHongYao Mar 3, 2023
7ba7c8e
Updated basic user guide
LimHongYao Mar 3, 2023
ca442dc
Added UserGuide documentation in docs directory for website
LimHongYao Mar 16, 2023
3fff458
fixed bug with exception handling
LimHongYao Mar 16, 2023
488a811
re-commit with missing DukeException file
LimHongYao Mar 16, 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
77 changes: 71 additions & 6 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 void exitMessage() {
System.out.println("Go away Anna");
System.out.println("O-kay bye......");
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Hi it's Anna!\nWhat do you need to do?");
Scanner in = new Scanner(System.in);

boolean exit = false;

Choose a reason for hiding this comment

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

Preferably name boolean in such a way that implies it is boolean.

Choose a reason for hiding this comment

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

Maybe use isExit to replace exit can imply a boolean

while (!exit) {
String input = (in.nextLine()).trim();
String inputCMD, inputItem;

Choose a reason for hiding this comment

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

Can I check what does CMD mean? If it stands for command. I think it's better to just name it as inputCommand for readibilty.

if (input.contains(" ")) {
inputCMD = input.split(" ", 2)[0];
inputItem = input.split(" ", 2)[1];

Choose a reason for hiding this comment

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

The numbers like 2, 0, 1 might be considered magic numbers that hinder readability.

} else {
inputCMD = input;
inputItem = null;
}

switch (inputCMD) {
case "bye":
exitMessage();
exit = true;
break;
case "list":
if (ToDoList.getNumItems() == 0) {
System.out.println("We are free! Let's go play!");
} else {
System.out.println("Here's what we've gotta do:");
ToDoList.viewList();
}
break;
case "mark":
if (inputItem == null) {
System.out.println("What should I mark?");
ToDoList.viewList();
inputItem = in.nextLine().trim();
}

Copy link

Choose a reason for hiding this comment

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

Do avoid leaving the space between each case as per the Java Coding Standards

ToDoList.markDone(Integer.parseInt(inputItem)-1);
System.out.println("Okay I've marked item " + inputItem + " as done:");
ToDoList.printItem(Integer.parseInt(inputItem)-1);

Choose a reason for hiding this comment

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

I like the single level of abstraction applied here. Makes things easy to follow

break;

case "unmark":
if (inputItem == null) {
System.out.println("What should I unmark?");
//TODO: add in handling if input is "unmark 2" again
ToDoList.viewList();
inputItem = in.nextLine().trim();
}

ToDoList.markNotDone(Integer.parseInt(inputItem)-1);
System.out.println("Oh no! Are we not done with " + inputItem + " after all?");
ToDoList.printItem(Integer.parseInt(inputItem)-1);
break;
case "add":
ToDoList.addItem(inputItem);
break;
default:
System.out.println("I didn't get that!");
break;
}
}
}
}




36 changes: 36 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

public class Task {
protected String description;
protected boolean isDone;

public Task(String description) { //ok to leave as public?
Copy link

Choose a reason for hiding this comment

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

Yes you need to leave it as public. But do remove such comments from your code as it goes against the java coding standard. 👍

this.description = description;
this.isDone = false;
}

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

public void setDescription(String description) {
this.description = description;
}

public void markDone() {
isDone = true;
}

public void markNotDone() {
isDone = false;
}

public String getDescription() {
return description;
}

public String getTask() {
String Task = "[";
return Task.concat(getStatusIcon() + "] " + getDescription());
}

}
42 changes: 42 additions & 0 deletions src/main/java/ToDoList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import java.util.ArrayList;

public class ToDoList {
private static final ArrayList<Task> TaskList = new ArrayList<>(10);

Choose a reason for hiding this comment

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

Maybe V\variable names need to be in camelCase.

Choose a reason for hiding this comment

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

Maybe variable names need to be in camelCase.

Choose a reason for hiding this comment

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

Maybe the size of the ArrayList should be a magic number.

private static int NumTasks = 0;

Choose a reason for hiding this comment

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

Maybe variable names must be in camelCase, same problem.

public static void addItem (String in) {
Task task = new Task(in);

TaskList.add(task);
NumTasks += 1;
System.out.println("added: " + in);
}
public static int getNumItems() {
return NumTasks;
}
public static void viewList () {
for (int i = 0; i < TaskList.size(); ++i) {
System.out.print(i+1 + ". ");

System.out.println(TaskList.get(i).getTask());
}
}
public static void markDone (int index) {
if (TaskList.get(index).getStatusIcon().equals(" ")) {

Choose a reason for hiding this comment

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

Is this if statement necessary? I think markDone would change the status icon to "X" independent of what is originally is

TaskList.get(index).markDone();
}
}
public static void markNotDone (int index) {
if (TaskList.get(index).getStatusIcon().equals("X")) {
TaskList.get(index).markNotDone();
}
}
public static Task getItem (int index) {
return TaskList.get(index);
}
public static void printItem (int index) {
System.out.print(index+1 + ". ");
System.out.println(TaskList.get(index).getTask());
}


}