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

[Teh Kok Hoe] iP #309

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
db7b3b9
Added a FastReader
tehkokhoe Jan 19, 2022
f5cc97c
Level-1
tehkokhoe Jan 19, 2022
3a03048
Level-2
tehkokhoe Jan 19, 2022
98dd74f
added new Class Task
tehkokhoe Jan 20, 2022
82e3f0b
Level-3
tehkokhoe Jan 20, 2022
666bf39
Level-4 Added enum and additional functions
tehkokhoe Jan 20, 2022
3e42bcc
added a default constructor
tehkokhoe Jan 20, 2022
2623e50
Added Deadline class
tehkokhoe Jan 20, 2022
2f2eae3
added Event class
tehkokhoe Jan 20, 2022
c6c76f9
added ToDo class
tehkokhoe Jan 20, 2022
7253df2
Remove spaces on toString() method
tehkokhoe Jan 22, 2022
cd2cec9
Update accessor of enum, add error handling, and change display.
tehkokhoe Jan 22, 2022
074b3d5
Add test.
tehkokhoe Jan 22, 2022
220ea0d
Add DukeException class
tehkokhoe Jan 22, 2022
575afdb
Add delete feature
tehkokhoe Jan 22, 2022
53d3490
Add test cases for delete feature
tehkokhoe Jan 22, 2022
d355645
Add different display method for tasks for record purposes
tehkokhoe Jan 31, 2022
fb0bb08
Revert "Add different display method for tasks for record purposes"
tehkokhoe Jan 31, 2022
613ba0f
Add different display method for tasks for record purposes
tehkokhoe Jan 31, 2022
7ab38ce
Add save method and fix to coding standard
tehkokhoe Jan 31, 2022
c5d5d5e
Fix code to coding standard
tehkokhoe Jan 31, 2022
d418108
Allow dates to be recognized as the object 'Date'
tehkokhoe Feb 8, 2022
74b2b4d
Fix coding standards
tehkokhoe Feb 8, 2022
0fe362e
Merge branch 'branch-Level-8'
tehkokhoe Feb 8, 2022
70a8771
Adjust how date is displayed and recorded
tehkokhoe Feb 24, 2022
603ab96
Make program more OOP like
tehkokhoe Feb 24, 2022
80b2d81
Fix how date is parsed in event
tehkokhoe Feb 24, 2022
4967046
Package all classes
tehkokhoe Feb 24, 2022
5c83648
Add exception handler for invalid commands
tehkokhoe Feb 25, 2022
1536f41
Let parseCommand throw IllegalArgumentException
tehkokhoe Feb 25, 2022
1ac0efb
Add JUnit tests
tehkokhoe Feb 25, 2022
9ced633
Add checkstyle tests
tehkokhoe Feb 25, 2022
d83efcc
Add JavaDoc
tehkokhoe Feb 25, 2022
1642bc7
Fix coding standards
tehkokhoe Feb 25, 2022
dc491b3
Add find function
tehkokhoe Feb 25, 2022
f9dfa90
Merge branch 'branch-A-JavaDoc'
tehkokhoe Feb 25, 2022
4fdd0ad
Merge branch 'branch-A-CodingStandard'
tehkokhoe Feb 25, 2022
f429a7d
Merge branch 'branch-Level-9'
tehkokhoe Feb 25, 2022
5bee490
Add JavaDoc for find methods
tehkokhoe Feb 25, 2022
2b64ac0
Make a GFMD
tehkokhoe Feb 25, 2022
7145edb
no message
tehkokhoe Feb 25, 2022
8d43a6c
Add GUI
tehkokhoe Feb 26, 2022
b94ab8b
Merge branch 'branch-Level-10'
tehkokhoe Feb 26, 2022
4a75f69
Adjust JavaDoc
tehkokhoe Feb 26, 2022
4e8656a
Add assert
tehkokhoe Feb 26, 2022
f70a410
Merge branch 'branch-A-Assertions'
tehkokhoe Feb 26, 2022
d2fa202
Add duplicate detector
tehkokhoe Feb 26, 2022
d172734
Change UI to make more sense
tehkokhoe Feb 26, 2022
c78b885
Set theme jekyll-theme-architect
tehkokhoe Feb 26, 2022
86ccd94
Add User Guide
tehkokhoe Feb 26, 2022
1ec936f
Merge branch 'master' of https://github.com/tehkokhoe/ip
tehkokhoe Feb 26, 2022
79edc3b
Update dateformat links in User Guide
tehkokhoe Feb 26, 2022
32b47dc
Adjusted coding quality issues
tehkokhoe Feb 26, 2022
1a2789b
Add Ui screenshot
tehkokhoe Feb 26, 2022
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
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Deadline extends Task {
private String by;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
158 changes: 157 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,166 @@
import java.util.*;
Copy link

Choose a reason for hiding this comment

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

Two things here:

  1. Keep everything in a package
  2. Only import things that are needed to be used. Avoid using wildcard imports


public class Duke {
enum Command {
Copy link

Choose a reason for hiding this comment

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

Good to see you're using enums for this! Keep it up.

BYE,
LIST,
MARK,
UNMARK,
TODO,
DEADLINE,
EVENT,
DELETE
;
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println(" ____________________________________________________________");
Copy link

Choose a reason for hiding this comment

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

Instead of using 4 spaces, you can consider using \t instead for tab

System.out.println(" Hello! I'm Duke");
System.out.println(" What can I do for you?");
System.out.println(" ____________________________________________________________");
boolean StillIn = true;
Copy link

Choose a reason for hiding this comment

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

Use camelCase to name variables, and booleans should be of the form isSomething. You could possibly rename this to isStillIn

FastReader fr = new FastReader();
ArrayList<Task> list = new ArrayList<Task>(100);
while(StillIn) {
Copy link

Choose a reason for hiding this comment

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

I think you need to put spacing between the brackets and each while and each if. You only do not use spaces when it is a function/method declaration

String in = fr.nextLine();
String[] input = in.split(" ", 2);
Command cmd = Command.valueOf(input[0].toUpperCase());
System.out.println(" ____________________________________________________________");
try {
switch (cmd) {
case BYE:
Copy link

Choose a reason for hiding this comment

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

case should not be indented. It should be on the same line as switch

System.out.println(bye());
StillIn = false;
break;

case LIST:
list(list);
break;

case MARK:
if(input.length < 2) {
throw new DukeException(" ☹ OOPS!!! I don't know what to mark");
}

int numMark = Integer.parseInt(input[1]);

if(numMark > list.size()) {
throw new DukeException(" ☹ OOPS!!! I don't see your task");
}

list.get(numMark - 1).setDone();
System.out.println(" Nice! I've marked this task as done:");
System.out.println(" " + list.get(numMark - 1));
break;

case UNMARK:
if(input.length < 2) {
throw new DukeException(" ☹ OOPS!!! I don't know what to unmark");
}

int numUnmark = Integer.parseInt(input[1]);

if(numUnmark > list.size()) {
throw new DukeException(" ☹ OOPS!!! I don't see your task");
}

list.get(numUnmark - 1).setUndone();
System.out.println(" OK, I've marked this task as not done yet:");
System.out.println(" " + list.get(numUnmark - 1));
break;

case TODO:
if(input.length < 2) {
throw new DukeException(" ☹ OOPS!!! The description of a todo cannot be empty");
}
Task todo = new ToDo(input[1]);
list.add(todo);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + todo);
System.out.printf(" Now you have %d task(s) in the list\n", list.size());
break;

case DEADLINE:
if(input.length < 2) {
throw new DukeException(" ☹ OOPS!!! The description of a deadline cannot be empty");
}
String[] splitbydate = input[1].split(" /by ");
if(splitbydate.length < 2) {
throw new DukeException(" ☹ OOPS!!! I don't know when your task is due");
}
String bydate = splitbydate[1];
Task deadline = new Deadline(splitbydate[0], bydate);
list.add(deadline);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + deadline);
System.out.printf(" Now you have %d task(s) in the list\n", list.size());
break;

case EVENT:
if(input.length < 2) {
throw new DukeException(" ☹ OOPS!!! The description of an event cannot be empty");
}
String[] splitatdate = input[1].split(" /at ");
if(splitatdate.length < 2) {
throw new DukeException(" ☹ OOPS!!! I don't know when your event happens");
}
String atdate = splitatdate[1];
Task event = new Event(splitatdate[0], atdate);
list.add(event);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + event);
System.out.printf(" Now you have %d task(s) in the list\n", list.size());
break;

case DELETE:
if(input.length < 2) {
throw new DukeException(" ☹ OOPS!!! I don't know what to delete");
}

int removenum = Integer.parseInt(input[1]);

if(removenum > list.size()) {
throw new DukeException(" ☹ OOPS!!! I don't see your task");
}

Task removedtask = list.remove(removenum - 1);
System.out.println(" Noted. I've removed this task:");
System.out.println(" " + removedtask);
System.out.printf(" Now you have %d task(s) in the list\n", list.size());
}
} catch(DukeException err) {
System.out.println(err.getMessage());
} catch(NumberFormatException err) {
System.out.println(" ☹ OOPS!!! Task number given is not suitable");
}
System.out.println(" ____________________________________________________________");
}
}

public static void list(ArrayList<Task> lst) {
for(int i=0; i < lst.size(); i++) {
if(i == 0) {
System.out.println(" Here are the tasks in your list:");
}
System.out.printf(" %d. %s\n", i + 1, lst.get(i));
}
if(lst.size() == 0) {
System.out.println(" There's nothing in your list");
}
}

public static String blah() {
return " blah";
}

public static String bye() {
return " Bye. Hope to see you again soon!";

}
}
}
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 @@
public class DukeException extends Exception {
public 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 at;

public Event(String task, String at) {
super(task);
this.at = at;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + at + ")";
}
}
51 changes: 51 additions & 0 deletions src/main/java/FastReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.io.BufferedReader;
Copy link

Choose a reason for hiding this comment

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

Not too sure if FastReader is required here, but good consideration!

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class FastReader {
BufferedReader br;
StringTokenizer st;

public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}

String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() { return Integer.parseInt(next()); }

long nextLong() { return Long.parseLong(next()); }

double nextDouble()
{
return Double.parseDouble(next());
}

String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}

50 changes: 50 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
public class Task {
private String task;
private boolean done;
Copy link

Choose a reason for hiding this comment

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

According to the coding standards, this should be named isDone


public Task() {
this.done = false;
}

public Task(String task) {
this.task = task;
this.done = false;
}

public String getTask() {
return task;
}

public void setDone() {
this.done = true;
}

public void setUndone() {
this.done = false;
}

@Override
public int hashCode() {
return task.hashCode();
}

@Override
public boolean equals(Object other) {
if(other instanceof Task){
Task toCompare = (Task) other;
return this.task.equals(toCompare.getTask());
}
return false;
}

@Override
public String toString() {
String temp;
if(this.done) {
temp = "X";
} else {
temp = " ";
}
return "[" + temp + "] " + this.task;
}
}
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 task) {
super(task);
}

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