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

[Guanlin] iP #187

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8d473bd
Increment Level 1
Feb 7, 2024
902153b
no message
Feb 7, 2024
37892d1
Level 1-1
Feb 7, 2024
8c29b77
Level-2
Feb 7, 2024
373d959
Level 3
Feb 8, 2024
6da7d59
Level 3
Feb 8, 2024
b832517
Level 4
Feb 14, 2024
ab3c2a2
A-CodeQuality
Feb 14, 2024
a5e25f4
Some clean up
Feb 15, 2024
c771a07
Level 5
Feb 18, 2024
068ec72
A-Packages with some exceptions refining
Feb 18, 2024
a0124d8
Added Array List Class
Feb 25, 2024
91efd3c
Added delete function to the bot
Feb 25, 2024
4ceb8bc
added file reading and writing along with some touch ups
Feb 25, 2024
fd754ce
made some changes according to TA comments
Feb 25, 2024
4b7773e
removed some magic numbers
Feb 25, 2024
2e7a416
Add UI class for future use
Mar 5, 2024
3d32a68
upload for PC use
Mar 6, 2024
abec695
add UI class and replaced body code with UI class
Mar 6, 2024
5b96b6d
add logic class and refactor code
Mar 6, 2024
2bfc693
add storage class and make main code more OOP
Mar 6, 2024
c447112
add TaskManager class and more OOP
Mar 7, 2024
f55da6d
add find function and create new IllegalArgumentException
Mar 7, 2024
0bc30b2
Merge pull request #1 from Fureimi/branch-Level-8
Fureimi Mar 7, 2024
e69231e
add javadoc comments to classes
Mar 7, 2024
976d60c
Merge branch 'master' of https://github.com/Fureimi/ip
Mar 7, 2024
96b0adc
Merge branch 'master' into branch-JavaDoc
Mar 7, 2024
d447eeb
Merge pull request #2 from Fureimi/branch-JavaDoc
Fureimi Mar 7, 2024
48ebd3d
add user guide
Mar 8, 2024
fc09fdc
do minor changes to readme formatting
Mar 8, 2024
6bd7337
do minor changes to README
Mar 8, 2024
09bebe3
change notes in readme
Mar 8, 2024
7107311
change ui and readme errors
Mar 8, 2024
6c21a23
clean up importing
Mar 8, 2024
f462c50
add error handling
Mar 8, 2024
9b642bc
import Tasks class
Mar 8, 2024
8f6b521
Merge branch 'master' into branch-Level-5
Mar 8, 2024
61d2e5a
Merge branch 'branch-Level-5'
Mar 8, 2024
0e69b9e
delete extra classes
Mar 8, 2024
d3581b7
add delete
Feb 25, 2024
b0ff90a
add save and loading
Feb 25, 2024
9f54241
Merge branch 'branch-Level-6'
Mar 8, 2024
35b1b33
Merge branch 'branch-Level-7'
Mar 8, 2024
a177300
final version of germabot (should be)
Mar 8, 2024
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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/Exceptions/EmptyTaskException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class EmptyTaskException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/MissingDeadlineException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class MissingDeadlineException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/MissingStartDateException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class MissingStartDateException extends Exception{
}
4 changes: 4 additions & 0 deletions src/main/java/Exceptions/UnknownInputException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Exceptions;

public class UnknownInputException extends Exception{
}
167 changes: 167 additions & 0 deletions src/main/java/MainRuntime/GermaBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package MainRuntime;

import Exceptions.EmptyTaskException;
import Exceptions.MissingDeadlineException;
import Exceptions.MissingStartDateException;
import Exceptions.UnknownInputException;
import Tasks.Deadline;
import Tasks.Event;
import Tasks.Task;
import Tasks.ToDo;

import java.util.Scanner;

public class GermaBot {
static int counter = 0;
static final String LINE= "____________________________________________";

Choose a reason for hiding this comment

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

good job on declaring constant

static Task[] toDoList = new Task[100];
public static int getIdx(String input) {
return Integer.parseInt(input.substring(input.indexOf(" ") + 1)) - 1;
}

public static void createTodo(String input) throws EmptyTaskException {
String toDoTask = input.substring(input.indexOf("todo ") + 5);

Choose a reason for hiding this comment

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

what is 5? do avoid magic numbers

if (toDoTask.isBlank()) {
throw new EmptyTaskException();
}
toDoList[counter] = new ToDo(toDoTask);
counter++;
System.out.println("Gotcha! Added '" + toDoTask + "' to your To Do List!");
}

public static void createDeadline(String input) throws EmptyTaskException, MissingDeadlineException {
String description = input.replaceFirst("deadline ", "");
if (description.equals("deadline")) {
throw new EmptyTaskException();
}
int idxOfEndDate = description.indexOf("/");
if (idxOfEndDate == -1) {
throw new MissingDeadlineException();
}
String date = description.substring( idxOfEndDate + 4);

Choose a reason for hiding this comment

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

what does 4 here stand for? do check through your code for more magic numbers

Choose a reason for hiding this comment

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

Suggested change
String date = description.substring( idxOfEndDate + 4);
String date = description.substring(idxOfEndDate + 4);

String toDoTask = description.substring(0, idxOfEndDate - 1);
if (toDoTask.isBlank()) {
throw new EmptyTaskException();
}
toDoList[counter] = new Deadline(description.substring(0, idxOfEndDate - 1), date);
counter++;
System.out.println("Gotcha! Added '" + toDoTask + "' to your To Do List!" +
" You have to finish this by " + date + ", so be reminded!");
}

public static void createEvent(String input) throws EmptyTaskException, MissingDeadlineException,
MissingStartDateException {
String description = input.replaceFirst("event ", "");
int idxOfFrom = description.indexOf("/from");
if (idxOfFrom == -1) {
throw new EmptyTaskException();
}
int idxOfBy = description.indexOf("/to");
if (idxOfBy == -1) {
throw new MissingDeadlineException();
}
String startDate = description.substring(idxOfFrom + 6, idxOfBy - 1);
if (startDate.isBlank()) {
throw new MissingStartDateException();
}
String endDate = description.substring(idxOfBy + 4);
if (endDate.isBlank()) {
throw new MissingDeadlineException();
}
String toDoTask = description.substring(0, idxOfFrom - 1);
if (toDoTask.isBlank()) {
throw new EmptyTaskException();
}
toDoList[counter] = new Event(description.substring(0, idxOfFrom - 1), startDate, endDate);
counter++;
System.out.println("Gotcha! Added '" + toDoTask + "' to your To Do List!" +
" This will happen from " + startDate + " to " + endDate + ", so please remember to mark it" +
" on your calender! (Or ask me!)");
}

public static void createTask(String input) throws UnknownInputException {
if (input.contains("todo")) {
try {
createTodo(input);
} catch (EmptyTaskException e) {
System.out.println("Uh oh, you did not specify a task to add! Let's try again!");
}
}
else if (input.contains("deadline")) {
try {
createDeadline(input);
} catch (EmptyTaskException e) {
System.out.println("Uh oh, you did not specify a task to add! Let's try again!");
} catch (MissingDeadlineException e) {
System.out.println("Uh oh, you did not specify the deadline! Let's try again!");
}

}

Choose a reason for hiding this comment

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

why is there a newline between these 2 brackets?

else if (input.contains("event")) {
try {
createEvent(input);
} catch (EmptyTaskException e) {
System.out.println("Uh oh, you did not specify a task to add! Let's try again!");
} catch (MissingStartDateException e) {
System.out.println("Uh oh, you did not specify a start time! Let's try again!");
} catch (MissingDeadlineException e) {
System.out.println("Uh oh, you did not specify the deadline! Let's try again!");
}
} else {
throw new UnknownInputException();
}
}

public static void main(String[] args) {

Choose a reason for hiding this comment

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

this method is very long, try to shorten it

String WelcomeMessage = "Hello! MainRuntime.GermaBot here! \n"
+ "What may I do for you this fine day?";
System.out.println(LINE);
System.out.println(WelcomeMessage);
System.out.println(LINE);
while (true) {
String input;
Scanner in = new Scanner(System.in);
input = in.nextLine();
if (input.equals("bye")) {
break;
}
if (input.equals("list")) {
if (toDoList[0] == null) {
System.out.println("Umm... You haven't added any Tasks yet... Let's try adding " +
"some now!");
} else {
int printCounter = 1;
System.out.println("Gotcha! Here are your tasks:");
for (int i = 0; i < counter; i++) {
if (toDoList[i] == null) {
break;
}
System.out.println(printCounter + ". " + toDoList[i].toString());
printCounter++;
}
}

Choose a reason for hiding this comment

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

this part is deeply nested, try to avoid deep nesting

} else if (input.contains("unmark")) {
int idx = getIdx(input);
toDoList[idx].setDone(false);
System.out.println("Aww, not done? Okay, I'll mark this task as undone: "
+ "[" + toDoList[idx].getStatusIcon() + "] " + toDoList[idx].getDescription());
} else if (input.contains("mark")) {
int idx = getIdx(input);
toDoList[idx].setDone(true);
System.out.println("Good job! I'll mark this task as done: "
+ "[" + toDoList[idx].getStatusIcon() + "] " + toDoList[idx].getDescription());
} else {
try {
createTask(input);
} catch (UnknownInputException e){
System.out.println("Uhh.. I'm sorry but I'm not quite sure what '" + input + "' means..." +
" Remember to include the Task Type in front of the input!!");
}
}
}
String GoodbyeMessage = "Thanks for using me! Hope to see you again soon~!";
System.out.println(LINE);
System.out.println(GoodbyeMessage);
System.out.println(LINE);
}
}
24 changes: 24 additions & 0 deletions src/main/java/Tasks/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Tasks;

public class Deadline extends Task {

protected String by;

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

public String getBy() {
return by;
}

public void setBy(String date) {
this.by = date;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
36 changes: 36 additions & 0 deletions src/main/java/Tasks/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package Tasks;

import Tasks.Task;

public class Event extends Task {

protected String from;
protected String to;

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

public String getFrom() {
return from;
}

public void setFrom(String from) {
this.from = from;
}

public String getTo() {
return to;
}

public void setTo(String to) {
this.to = to;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}
}
36 changes: 36 additions & 0 deletions src/main/java/Tasks/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package Tasks;

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 void setDescription(String description) {
this.description = description;
}

public boolean isDone() {
return isDone;
}

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

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

@Override
public String toString() {
return "[" + this.getStatusIcon() + "] " + this.getDescription();
}
}
14 changes: 14 additions & 0 deletions src/main/java/Tasks/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package Tasks;

import Tasks.Task;

public class ToDo extends Task {
public ToDo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}