-
Notifications
You must be signed in to change notification settings - Fork 200
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
waiter-palypoo
wants to merge
31
commits into
nus-cs2113-AY2223S2:master
Choose a base branch
from
waiter-palypoo:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[waiter-palypoo] ip #193
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 0e9f153
Refactor greeting message and add handleCommand method to echo user i…
waiter-palypoo 565a8e1
Add code for adding items to a list and printing the list
waiter-palypoo 3d00890
Add Task class, add code to mark and unmark tasks
waiter-palypoo 7e758c3
Add support for todo, deadline and event task types.
waiter-palypoo e13adce
no message
waiter-palypoo 752a280
Merge commit '7e758c3a91d41d43006c379c502de1ceb83a4e1f' into HEAD
waiter-palypoo c47e253
Resolved error resulting from RCS mistake
waiter-palypoo e40dfd0
Add code to handle unknown command, insufficient detail exceptions.
waiter-palypoo 203f936
Merge branch 'branch-Level-5'
waiter-palypoo 367c9fd
Divide classes into packages
waiter-palypoo 65eef30
Add method to delete tasks, fixed coding standard violations, change …
waiter-palypoo c890a60
Add functionality to save task list to a .txt file.
waiter-palypoo 07e9a22
Merge branch 'branch-Level-6'
waiter-palypoo 1071390
Merge branch 'branch-Level-7'
waiter-palypoo 3b7e16a
Refactor functionality into Parser, Ui, Storage and TaskList classes.
waiter-palypoo b0dc677
Add date-time format support
waiter-palypoo 2f02a85
Add method to search for items by matching substrings in Task descrip…
waiter-palypoo 0e9aa9a
Merge pull request #1 from waiter-palypoo/branch-Level-8
waiter-palypoo 4af6cef
Merge branch 'master' of https://github.com/waiter-palypoo/ip
waiter-palypoo da2844c
Merge branch 'master' into branch-Level-9
waiter-palypoo 4c64d87
Merge pull request #2 from waiter-palypoo/branch-Level-9
waiter-palypoo bf6fe2d
Merge branch 'master' of https://github.com/waiter-palypoo/ip into br…
waiter-palypoo 4e01561
Merge branch 'branch-Level-9'
waiter-palypoo ecce69f
Optimise imports for Deadline and Event classes
waiter-palypoo 019af43
Add JavaDoc comments for multiple classes and methods. Refactor some …
waiter-palypoo c915504
Merge pull request #3 from waiter-palypoo/branch-A-JavaDoc
waiter-palypoo b195b1d
Merge branch 'master' of https://github.com/waiter-palypoo/ip
waiter-palypoo 5a621ec
Updated user guide, changed find method to print the index of matchin…
waiter-palypoo 29dcae7
Fix bugs involving invalid inputs for mark, unmark and delete methods
waiter-palypoo d207461
Build jar file
waiter-palypoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package hina.exceptions; | ||
|
||
public class HinaException extends Throwable { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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