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

[waiter-palypoo] ip #193

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7faa1cb
Add HinaBot.java
waiter-palypoo Jan 26, 2023
0e9f153
Refactor greeting message and add handleCommand method to echo user i…
waiter-palypoo Jan 27, 2023
565a8e1
Add code for adding items to a list and printing the list
waiter-palypoo Jan 31, 2023
3d00890
Add Task class, add code to mark and unmark tasks
waiter-palypoo Feb 1, 2023
7e758c3
Add support for todo, deadline and event task types.
waiter-palypoo Feb 1, 2023
e13adce
no message
waiter-palypoo Feb 1, 2023
752a280
Merge commit '7e758c3a91d41d43006c379c502de1ceb83a4e1f' into HEAD
waiter-palypoo Feb 1, 2023
c47e253
Resolved error resulting from RCS mistake
waiter-palypoo Feb 1, 2023
e40dfd0
Add code to handle unknown command, insufficient detail exceptions.
waiter-palypoo Feb 14, 2023
203f936
Merge branch 'branch-Level-5'
waiter-palypoo Feb 14, 2023
367c9fd
Divide classes into packages
waiter-palypoo Feb 14, 2023
65eef30
Add method to delete tasks, fixed coding standard violations, change …
waiter-palypoo Feb 28, 2023
c890a60
Add functionality to save task list to a .txt file.
waiter-palypoo Feb 28, 2023
07e9a22
Merge branch 'branch-Level-6'
waiter-palypoo Feb 28, 2023
1071390
Merge branch 'branch-Level-7'
waiter-palypoo Feb 28, 2023
3b7e16a
Refactor functionality into Parser, Ui, Storage and TaskList classes.
waiter-palypoo Mar 1, 2023
b0dc677
Add date-time format support
waiter-palypoo Mar 2, 2023
2f02a85
Add method to search for items by matching substrings in Task descrip…
waiter-palypoo Mar 2, 2023
0e9aa9a
Merge pull request #1 from waiter-palypoo/branch-Level-8
waiter-palypoo Mar 2, 2023
4af6cef
Merge branch 'master' of https://github.com/waiter-palypoo/ip
waiter-palypoo Mar 2, 2023
da2844c
Merge branch 'master' into branch-Level-9
waiter-palypoo Mar 2, 2023
4c64d87
Merge pull request #2 from waiter-palypoo/branch-Level-9
waiter-palypoo Mar 2, 2023
bf6fe2d
Merge branch 'master' of https://github.com/waiter-palypoo/ip into br…
waiter-palypoo Mar 2, 2023
4e01561
Merge branch 'branch-Level-9'
waiter-palypoo Mar 2, 2023
ecce69f
Optimise imports for Deadline and Event classes
waiter-palypoo Mar 2, 2023
019af43
Add JavaDoc comments for multiple classes and methods. Refactor some …
waiter-palypoo Mar 3, 2023
c915504
Merge pull request #3 from waiter-palypoo/branch-A-JavaDoc
waiter-palypoo Mar 3, 2023
b195b1d
Merge branch 'master' of https://github.com/waiter-palypoo/ip
waiter-palypoo Mar 3, 2023
5a621ec
Updated user guide, changed find method to print the index of matchin…
waiter-palypoo Mar 3, 2023
29dcae7
Fix bugs involving invalid inputs for mark, unmark and delete methods
waiter-palypoo Mar 17, 2023
d207461
Build jar file
waiter-palypoo Mar 17, 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
118 changes: 118 additions & 0 deletions src/main/java/hina/HinaBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package hina;

import hina.exceptions.HinaException;
import hina.task.Deadline;
import hina.task.Event;
import hina.task.Task;

import java.util.Scanner;

public class HinaBot {
protected static Task[] taskList = new Task[100];
protected static int taskCount = 0;

public static void main(String[] args) {
String line;
Scanner in = new Scanner(System.in);
showGreeting();
while (true) {
try {
line = in.nextLine();
handleCommand(line);
} catch (HinaException cmdException) {
System.out.println(">.< Hina does not recognise this command!");
} catch (StringIndexOutOfBoundsException argException) {
System.out.println("@_@ Please give Hina more details!");
}
}
}

private static void showGreeting() {
System.out.println("Hello master!");
System.out.println("What are your orders?");
}

public static void handleCommand(String command) throws HinaException {
if (command.equalsIgnoreCase("bye")) {
System.out.println("Goodbye master, let's meet again soon...");
System.exit(0);
} else if (command.equalsIgnoreCase("list")) {
listTasks();
} else if (command.split(" ")[0].equalsIgnoreCase("mark")) {
int taskIndex = Integer.parseInt(command.split(" ")[1]);
markTask(taskIndex);
} else if (command.split(" ")[0].equalsIgnoreCase("unmark")) {
int taskIndex = Integer.parseInt(command.split(" ")[1]);
unmarkTask(taskIndex);
} else if (command.split(" ")[0].equalsIgnoreCase("todo")) {
addTask(command.substring(5));
} else if (command.split(" ")[0].equalsIgnoreCase("deadline")) {
addDeadline(command.substring(9));
} else if (command.split(" ")[0].equalsIgnoreCase("event")) {
addEvent(command.substring(6));
} else {
throw new HinaException();
}
}
Copy link

Choose a reason for hiding this comment

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

Good job of splitting a big method into smaller one and improving your code quality


public static void addTask(String description) {
Task newTask = new Task(description);
taskList[taskCount] = newTask;
taskCount++;
System.out.println("Noted! This task has been added:");
System.out.println(newTask.toString());
getTaskCount();
}

public static void listTasks() {
for (int i = 0; i < taskCount; i++) {
System.out.print(i + 1);
System.out.print(". ");
System.out.println(taskList[i].toString());
}
}

public static void markTask(int taskIndex) {
taskList[taskIndex - 1].setDone(true);
System.out.println("Roger that! This task is marked as done: ");
System.out.println(taskList[taskIndex - 1].toString());
}

public static void unmarkTask(int taskIndex) {
taskList[taskIndex - 1].setDone(false);
System.out.println("Roger that! This task is marked as not done: ");
System.out.println(taskList[taskIndex - 1].toString());
}

public static void addDeadline(String deadline) {
String[] details = deadline.split("/");
if (details.length < 2) {
System.out.println("Hina needs to know the deadline for this task!");
} else {
Deadline newDeadline = new Deadline(details[0], details[1].substring(3));
taskList[taskCount] = newDeadline;
taskCount++;
System.out.println("Noted! This task has been added:");
System.out.println(newDeadline.toString());
getTaskCount();
}
}

public static void addEvent(String event) {
String[] details = event.split("/");
if (details.length < 3) {
System.out.println("Please tell Hina when this event starts and ends!");
} else {
Event newEvent = new Event(details[0], details[1].substring(5).trim(), details[2].substring(3));
taskList[taskCount] = newEvent;
taskCount++;
System.out.println("Noted! This task has been added:");
System.out.println(newEvent.toString());
getTaskCount();
}
}

public static void getTaskCount() {
System.out.printf("There are %d items on your list.\n", taskCount);
}
}
4 changes: 4 additions & 0 deletions src/main/java/hina/exceptions/HinaException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package hina.exceptions;

public class HinaException extends Throwable {
}
22 changes: 22 additions & 0 deletions src/main/java/hina/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hina.task;

import hina.task.Task;

public class Deadline extends Task {
private String by;
public Deadline(String description, String by) {
super(description);
this.by = by;
}

public String toString() {
String mark;
if (super.isDone()) {
mark = "X";
}
else {
mark = " ";
}
return String.format("[D][%s] %s (by: %s)", mark, super.getDescription(), by);
}
}
24 changes: 24 additions & 0 deletions src/main/java/hina/task/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hina.task;

import hina.task.Task;

public class Event extends Task {
private String from;
private String to;
public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}

public String toString() {
String mark;
if (super.isDone()) {
mark = "X";
}
else {
Copy link

Choose a reason for hiding this comment

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

Same problem with my comment in Task

mark = " ";
}
return String.format("[D][%s] %s(from: %s to: %s)", mark, super.getDescription(), from, to);
}
}
37 changes: 37 additions & 0 deletions src/main/java/hina/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hina.task;

public class Task {
private String description;
private boolean isDone;
public boolean isDone() {
return isDone;
}

public void setDone(boolean done) {
isDone = done;
}

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

public String getDescription() {
return description;
}

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

public String toString() {
String mark;
if (isDone) {
mark = "X";
}
else {
Copy link

Choose a reason for hiding this comment

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

else should be on the same line with }

mark = " ";
}
return String.format("[T][%s] %s", mark, description);
}
}