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

[kenzantonius] iP #378

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
d0da323
Add Level 1
Jan 18, 2023
9395dc6
Add Level 2
Jan 18, 2023
2a3787e
Add Level 3
Jan 26, 2023
c76707f
Add Level 4
Jan 26, 2023
2d45761
Add level 5
Jan 30, 2023
5b12a41
Add level 6
Jan 31, 2023
5506608
Add level 7
Feb 13, 2023
30e51fb
Add level 8
Feb 13, 2023
e125b5f
no message
Feb 19, 2023
c47d8ac
Merge branch 'branch-Level-7'
Feb 19, 2023
462d127
no message
Feb 19, 2023
502bbbc
Merge branch 'branch-Level-8'
Feb 19, 2023
cedbe55
Make the code more OOP
Feb 19, 2023
14a39a6
Merge branch 'branch-A-MoreOOP'
Feb 19, 2023
0843b84
Divide classes into packages
Feb 19, 2023
1fcdf42
Merge branch 'branch-A-Packages'
Feb 19, 2023
1bbfa6a
Merge branch 'add-gradle-support'
Feb 19, 2023
f8939fc
Add JUnit tests to test the behavior of the code
Feb 19, 2023
90e04a4
Add JavaDoc comments to the code.
Feb 20, 2023
96be1dc
Merge branch 'branch-A-JavaDoc'
Feb 20, 2023
e864b36
Tweak the code to comply with a coding standard.
Feb 20, 2023
d70d794
Merge branch 'branch-A-CodingStandard'
Feb 20, 2023
44be10d
Implement Level 9. Give users a way to find a task by searching for a…
Feb 20, 2023
fb0b9d4
Merge branch 'branch-Level-9'
Feb 20, 2023
710f5ef
Implement Level 10. Add a GUI to Duke.
Feb 20, 2023
bbce7ed
Merge branch 'branch-Level-10'
Feb 20, 2023
913f4bf
Use Assertions.
Feb 20, 2023
f8f798a
Improve code quality.
Feb 20, 2023
3f90dae
Merge pull request #2 from kenzantonius/branch-A-Assertions
kenzantonius Feb 20, 2023
2ba8057
Merge pull request #3 from kenzantonius/branch-A-CodeQuality
kenzantonius Feb 20, 2023
e16deb6
Merge branch 'master' of https://github.com/kenzantonius/ip
Feb 20, 2023
0e40946
Add Ui.png.
Feb 20, 2023
cd96457
Update README.md
kenzantonius Feb 20, 2023
6bd37c2
Merge branch 'master' of https://github.com/kenzantonius/ip
Feb 20, 2023
94f55bf
Fix bugs.
Mar 2, 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
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 {

protected String by;

Choose a reason for hiding this comment

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

Maybe change name from by to something that is a noun


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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
149 changes: 141 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,143 @@
import java.util.Scanner;

import java.util.ArrayList;

public class Duke {
private Scanner scanner = new Scanner(System.in);
private ArrayList<Task> list = new ArrayList<>();

Choose a reason for hiding this comment

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

Maybe use plural form in a collection name? Like "tasks"?

private void Input() {

Choose a reason for hiding this comment

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

Shouldn't this method name be in camelCase?

while (true) {
String userInput = this.scanner.nextLine();
try{
if (userInput.equals("bye")) {
this.exit();
break;
}
if (userInput.equals("list")) {
this.showList();
continue;
}
if (userInput.startsWith("mark")) {
int taskNum = Integer.parseInt(userInput.substring(5));
this.markTask(taskNum);
continue;
}
if (userInput.startsWith("unmark")) {
int taskNum = Integer.parseInt(userInput.substring(7));
this.unmarkTask(taskNum);
continue;
}
if (userInput.startsWith("todo")) {
String todo = userInput.replace("todo", "");
emptyTodo(todo);
addTodo(todo);
continue;
}
if (userInput.startsWith("event")) {
String[] event = ErrorEventOrDeadline(userInput, "event", "/at");

Choose a reason for hiding this comment

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

Maybe use plural form for array name?

addEvent(event[0], event[1]);
continue;
}
if (userInput.startsWith("deadline")) {
String[] deadline = ErrorEventOrDeadline(userInput, "deadline", "/by");

Choose a reason for hiding this comment

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

Maybe use plural form for array name?

addDeadline(deadline[0], deadline[1]);
continue;
}
if (userInput.startsWith("delete")) {
deleteTask(Integer.parseInt(userInput.substring(7)));
continue;
}
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
} catch (DukeException exception) {
printMessage(exception.getMessage());
}
}
}

private void emptyTodo(String todo) throws DukeException {
if (todo.isEmpty()) {
throw new DukeException("☹ OOPS!!! The description of a todo cannot be empty.");
}
}

private String[] ErrorEventOrDeadline(String input, String textToReplace, String textToSplit) throws DukeException {

Choose a reason for hiding this comment

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

Maybe use verbs and camelCase for method names? Say, "makeErrEventOrDdl"

String[] splitInput = input.replaceFirst(textToReplace, "")

Choose a reason for hiding this comment

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

Maybe use plural form for array name?

.trim().split(textToSplit);

for (int i = 0; i < splitInput.length; i++) {
splitInput[i] = splitInput[i].trim();
}

if (splitInput.length != 2 || splitInput[0].isBlank() || splitInput[1].isBlank()) {
throw new DukeException("☹ OOPS!!! Please make sure the date is not empty");
}
return splitInput;
}

private void addTodo(String description) {
Todo newTodo = new Todo(description);
list.add(newTodo);
System.out.println("\tGot it. I've added this task:");
System.out.println("\t\t" + newTodo);
System.out.println("\tNow you have " + list.size() + " tasks in the list.");
}

private void addDeadline(String description, String by) {
Deadline newDeadline = new Deadline(description, by);
list.add(newDeadline);
System.out.println("\tGot it. I've added this task:");
System.out.println("\t\t" + newDeadline);
System.out.println("\tNow you have " + list.size() + " tasks in the list.");
}

private void addEvent(String description, String from) {
Event newEvent = new Event(description, from);
list.add(newEvent);
System.out.println("\tGot it. I've added this task:");
System.out.println("\t\t" + newEvent);
System.out.println("\tNow you have " + list.size() + " tasks in the list.");
}

private void markTask(int taskNum) {
this.list.get(taskNum - 1).markAsDone();
System.out.println("\tNice! I've marked this task as done:");
System.out.println("\t" + this.list.get(taskNum - 1) + "\n");
}

private void unmarkTask(int taskNum) {
this.list.get(taskNum - 1).markAsUndone();
System.out.println("\tOK, I've marked this task as not done yet:");
System.out.println("\t" + this.list.get(taskNum - 1) + "\n");
}

private void deleteTask(int taskNum) {
Task deletedTask = list.get(taskNum - 1);
list.remove(taskNum - 1);
System.out.println("\tNoted. I've removed this task:");
System.out.println("\t\t" + deletedTask);
System.out.printf("\tNow you have " + list.size() + " tasks in the list." + "\n");
}

private void showList() {
System.out.println("\tHere are the tasks in your list:");
for (int i = 1; i <= this.list.size(); i++) {
System.out.println("\t" + i + ". " + this.list.get(i - 1));
}
System.out.println();
}

private void exit() {
System.out.println("\tBye, hope to see you again!");
}

private void printMessage(String message) {
System.out.println("\t" + message);
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
}
}
Duke duke = new Duke();
System.out.println("Welcome! I'm Duke.");
System.out.println("What can I do for you?\n");
duke.Input();
}
}
5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DukeException extends Exception {
DukeException(String message) {
super(message);
}
}
13 changes: 13 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Event extends Task {
private String from;

Choose a reason for hiding this comment

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

similarly, conisder changing from to a noun


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

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + this.from + ")";
}
}
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 {
protected String description;
protected boolean isDone;

Choose a reason for hiding this comment

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

nice following convention


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 String.format("[%s] %s", this.getStatusIcon(), this.description);
}
}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
9 changes: 2 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Welcome! I'm Duke.
What can I do for you?