-
Notifications
You must be signed in to change notification settings - Fork 184
ParthGandhiNUS iP #174
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
base: master
Are you sure you want to change the base?
ParthGandhiNUS iP #174
Changes from 13 commits
29a97db
79d3451
8a51274
72d11f6
25ed6a7
99c3382
125183c
985febc
7aad7dd
0c82222
9fcbffb
0daa13c
6a9de55
49a8435
e46036a
fac8ce4
5c1ccf8
f81854a
623ce3a
431ab81
7239352
0f62b00
e6e5d36
e594cc7
b44385c
ac9ed1e
2d77b06
f47b008
2773484
d957c3e
42cb726
8430048
f8440df
4f0fddc
9fd02bf
c844f4b
960551a
bf338ba
a7db579
1cc2e52
9b6a2d9
2bd8515
aa6004d
882f346
06b6d9c
257227c
0458366
6240618
ea0db83
b2fd792
d188010
1afcfa5
b12bf13
5e2b8da
a5a2dd6
187e8fc
0581953
04ffa8a
a77e317
665139d
73eac78
9cca73a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| public class Deadline extends Task { | ||
|
|
||
| protected String by; | ||
|
|
||
| public Deadline(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[D]" + super.toString() + " (by: " + by + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| public class Event extends Task { | ||
| protected String startDayAndTime; | ||
| protected String endDayAndTime; | ||
|
|
||
| public Event (String description, String startDayAndTime, String endDayAndTime) { | ||
| super(description); | ||
| this.startDayAndTime = startDayAndTime; | ||
| this.endDayAndTime = endDayAndTime; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + " (from: " + startDayAndTime + " to: " + endDayAndTime + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| import java.util.Scanner; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.InputMismatchException; | ||
|
|
||
|
|
||
| public class Kowalski { | ||
|
|
||
| private static final String DIVIDING_LINE = "____________________________________________________________"; | ||
|
|
||
| public static List <Task> currentTask = new ArrayList<>(); | ||
|
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. Plural form should be used on names representing a collection of objects. https://se-education.org/guides/conventions/java/basic.html#naming |
||
| public static Scanner in = new Scanner (System.in); | ||
|
|
||
| /** | ||
| * Prints out the message introducing the functionalities of Kowalski Bot | ||
| */ | ||
| public static void printIntro(){ | ||
|
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.
|
||
| System.out.println(DIVIDING_LINE); | ||
| System.out.println("Welcome Skipper! I'm Kowalski, reporting for Duty!" + System.lineSeparator() + | ||
| "What can I do for you today?" ); | ||
| System.out.println(DIVIDING_LINE); | ||
| } | ||
|
|
||
| /** | ||
| * Used to check if the user has accurately input the deadline by stating the "/by" | ||
| * @param deadlineDetails : Contains the details of the deadline task | ||
| * @throws KowalskiException In the event that the input has no "/by" | ||
| */ | ||
| public static void checkDeadlineInput(String deadlineDetails) throws KowalskiException{ | ||
| if (!(deadlineDetails.contains("/by"))) { | ||
| throw new KowalskiException(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Used to check if the user has accurately input the deadline by stating the "/from" and "/to" | ||
| * @param eventDetails : Contains the details of the event task | ||
| * @throws KowalskiException In the event that the input has no "/from" or "/to" or both | ||
| */ | ||
| public static void checkEventInput(String eventDetails) throws KowalskiException{ | ||
| if (!((eventDetails.contains("/from")) && (eventDetails.contains("/to")))) { | ||
| throw new KowalskiException(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Used to process the different variations of the users inputs | ||
| * @param userInput : String which the user inputs | ||
| * @return String which is in lowercase and clear of any unnecessary whitespace | ||
| */ | ||
| public static String processInput(String userInput){ | ||
|
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. use the name to explain what the function does. perhaps you could name it |
||
| return (userInput.trim()).toLowerCase(); | ||
| } | ||
|
|
||
| /** | ||
| * Prints out an accurate message for the number of tasks in the list. | ||
| * @param number : represents the total current task count | ||
| */ | ||
| public static void printCurrentTaskMessage(int number){ | ||
|
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. the name |
||
| switch (number){ | ||
| case 0: | ||
| System.out.println("Now you have 0 tasks in the list."); | ||
| break; | ||
| case 1: | ||
| System.out.println("Now you have 1 task in the list."); | ||
| break; | ||
| default: | ||
| System.out.println("Now you have " + number + " tasks in the list."); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Used in the "list" command to print all the Current Tasks in the proper format | ||
| */ | ||
| public static void printCurrentTaskItems(){ | ||
| for (int i = 1; i <= currentTask.size(); i++){ | ||
| System.out.println(i + "." + currentTask.get(i-1)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Cleans up the user input and forms new Deadline Task | ||
| * @param deadlineDetails : User input for details of the deadline task | ||
| * @return new deadline task created | ||
| */ | ||
| private static Task getNewDeadlineTask(String deadlineDetails) { | ||
| String[] deadlineArray = deadlineDetails.split("/by"); | ||
| for (int i = 0; i < deadlineArray.length; i++) { | ||
| deadlineArray[i] = deadlineArray[i].trim(); | ||
| } | ||
|
|
||
|
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. remove one empty line (unnecessary whitespace) |
||
|
|
||
| return new Deadline(deadlineArray[0], deadlineArray[1]); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Cleans up the user input and forms new event Task | ||
| * @param eventDetails : User input for details of the event task | ||
| * @return new event task created | ||
| */ | ||
| private static Task getNewEventTask(String eventDetails) { | ||
| String[] eventArray = eventDetails.split("/from"); | ||
| String eventInformation = eventArray[0].trim(); | ||
|
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. avoid magic literals by storing these as static final vars |
||
| String [] fromAndTo = eventArray[1].split("/to"); | ||
|
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. array specifiers should be attached to the type |
||
| String eventFrom = fromAndTo[0].trim(); | ||
| String eventTo = fromAndTo[1].trim(); | ||
|
|
||
| return new Event(eventInformation, eventFrom, eventTo); | ||
| } | ||
|
|
||
| /** | ||
| * Processes all the inputs from the user and categorises the User Commands | ||
| * @param UserCommand: The first word input by the user | ||
| */ | ||
| public static void parseUserCommand(String UserCommand) { | ||
|
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. this function is very long (>>30 LOC). consider separating the code into multiple functions |
||
|
|
||
| int taskNumber; | ||
| int lastTaskIndex; | ||
| String remainingCommand; | ||
|
|
||
| switch (UserCommand){ | ||
| case "bye": | ||
| break; | ||
|
|
||
| case "list": | ||
|
|
||
| printCurrentTaskItems(); | ||
| System.out.println(DIVIDING_LINE); | ||
| break; | ||
|
|
||
| case "unmark": | ||
| try { | ||
| taskNumber = in.nextInt(); | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("Skipper input a god damn number! I am now gonna add the text which you inputted into our list!"); | ||
| break; | ||
| } | ||
|
|
||
| try{ | ||
| currentTask.get(taskNumber - 1).markAsNotDone(); | ||
| System.out.println( "C'mon Skipper, you're much better than that! I've marked this task as undone:"); | ||
| System.out.println(" " + currentTask.get(taskNumber - 1)); | ||
| } catch (IndexOutOfBoundsException e) { | ||
| System.out.println("Invalid Task Number! Skipper stop acting like Private!"); | ||
| } | ||
| System.out.println(DIVIDING_LINE); | ||
| break; | ||
|
|
||
| case "mark": | ||
| try { | ||
| taskNumber = in.nextInt(); | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("Skipper input a god damn number! I am now gonna add the text which you inputted into our list!"); | ||
| break; | ||
| } | ||
|
|
||
| try{ | ||
|
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. spacing |
||
| currentTask.get(taskNumber - 1).markAsDone(); | ||
| System.out.println( "Way to go Skipper! I've marked this task as done:"); | ||
| System.out.println(" " + currentTask.get(taskNumber - 1)); | ||
| } catch (IndexOutOfBoundsException e) { | ||
| System.out.println("Invalid Task Number! Skipper stop acting like Private!"); | ||
| } | ||
| System.out.println(DIVIDING_LINE); | ||
| break; | ||
|
|
||
| case "todo": | ||
| String toDoDetails = in.nextLine(); | ||
|
|
||
| Task newToDoTask = new Todo(toDoDetails.trim()); | ||
| currentTask.add(newToDoTask); | ||
| lastTaskIndex = currentTask.size() - 1; | ||
|
|
||
| System.out.println("Skipper you've got this work to do:"); | ||
| System.out.println(" " + currentTask.get( lastTaskIndex)); | ||
| printCurrentTaskMessage(currentTask.size()); | ||
| System.out.println(DIVIDING_LINE); | ||
| break; | ||
|
|
||
| case "deadline": | ||
| String deadlineDetails = in.nextLine(); | ||
|
|
||
| try{ | ||
| checkDeadlineInput(deadlineDetails); | ||
|
|
||
| //Adding the new deadline task into currentTask List after processing and cleaning inputs | ||
| Task newDeadlineTask = getNewDeadlineTask(deadlineDetails); | ||
| currentTask.add(newDeadlineTask); | ||
| lastTaskIndex = currentTask.size() - 1; | ||
|
|
||
| //Printing the appropriate information for the User | ||
| System.out.println("Skipper, I have recorded this deadline:"); | ||
| System.out.println(" " + currentTask.get( lastTaskIndex)); | ||
| printCurrentTaskMessage(currentTask.size()); | ||
| System.out.println(DIVIDING_LINE); | ||
| } catch (KowalskiException e){ | ||
| System.out.println("Skipper your inputs are wrong! Try again!"); | ||
| System.out.println(DIVIDING_LINE); | ||
| } | ||
| break; | ||
|
|
||
| case "event": | ||
| String eventDetails = in.nextLine(); | ||
|
|
||
| try{ | ||
| checkEventInput(eventDetails); | ||
|
|
||
| //Adding the new event task into currentTask List after processing and cleaning inputs | ||
| Task newEventTask = getNewEventTask(eventDetails); | ||
| currentTask.add(newEventTask); | ||
| lastTaskIndex = currentTask.size() - 1; | ||
|
|
||
| //Printing the appropriate information for the User | ||
| System.out.println("Skipper I've noted this event in my calendar:"); | ||
| System.out.println(" " + currentTask.get(lastTaskIndex)); | ||
| printCurrentTaskMessage(currentTask.size()); | ||
| System.out.println(DIVIDING_LINE); | ||
| } catch (KowalskiException e) { | ||
| System.out.println("Skipper your inputs are wrong! Try again!"); | ||
| System.out.println(DIVIDING_LINE); | ||
| } | ||
| break; | ||
|
|
||
|
|
||
| default: | ||
| remainingCommand = in.nextLine(); | ||
| Task newTask = new Task(UserCommand + remainingCommand); | ||
| currentTask.add(newTask); | ||
| System.out.println("added: " + UserCommand + remainingCommand); | ||
| System.out.println(DIVIDING_LINE); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Prints out the message to end conversation with the user | ||
| */ | ||
| public static void printEndConversation(){ | ||
| System.out.println("Bye Skipper! Hope to serve you again for your next mission!"); | ||
| System.out.println(DIVIDING_LINE); | ||
| } | ||
|
|
||
| public static void main(String[] args){ | ||
| printIntro(); | ||
| String userCommand = processInput(in.next()); | ||
|
|
||
| while (!(userCommand.equals("bye"))){ | ||
| parseUserCommand(processInput(userCommand)); | ||
| userCommand = in.next(); | ||
| } | ||
|
|
||
| printEndConversation(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| public class KowalskiException extends Exception{ | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
|
|
||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
|
|
||
| public void markAsNotDone(){ | ||
|
|
||
| this.isDone = false; | ||
| } | ||
| public void markAsDone(){ | ||
|
|
||
| this.isDone = true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[" + getStatusIcon() + "] " + getDescription(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| public class Todo extends Task { | ||
|
|
||
| public Todo(String description){ | ||
| super(description); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[T]" + super.toString(); | ||
| } | ||
| } |
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.
overall good use of javadoc comments