Skip to content

[Ee Hong Zhi] ip #78

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
19 changes: 19 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Deadline extends Task{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class Deadline extends Task{
public class Deadline extends Task {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

private String deadline;
public Deadline(String description, String deadline){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public Deadline(String description, String deadline){
public Deadline(String description, String deadline) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

Choose a reason for hiding this comment

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

Suggested change
public Deadline(String description, String deadline){
public Deadline(String description, String deadline) {

Similar to most of your methods, do remember to leave a space between the closing parenthesis and the opening curly brace.

super(description);
this.deadline = deadline;
}

@Override
public void show(){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void show(){
public void show() {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.print("[D][");
if(isDone){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(isDone){
if (isDone) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions. It is also suggested to add a space after if.

System.out.print("X");
}
else{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else{
} else {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

System.out.print(" ");
}
System.out.println("] " + description + " (by: " + deadline + ")");
}
}
135 changes: 127 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,129 @@
import java.util.Scanner;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
static private Task[] taskList = new Task[100];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static private Task[] taskList = new Task[100];
static private Task[] tasks = new Task[100];

Copy link
Member

Choose a reason for hiding this comment

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

Plural form should be used on names representing a collection of objects.

static private int numTasks = 0;

public static void printLine(){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static void printLine(){
public static void printLine() {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.println("____________________________________________________________");
}
}

public static void main(String[] args){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static void main(String[] args){
public static void main(String[] args) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.


System.out.println("Hello! I'm TheChattyFatty");

Scanner scanner = new Scanner(System.in);

while(true) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
while(true) {
while (true) {

Copy link
Member

Choose a reason for hiding this comment

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

It is suggested to add a space after while.

printLine();
System.out.println("What can I do for you?");
String response = scanner.nextLine();

// For handling keyword responses with multiple words
String[] words = response.split(" ");

String keyword = words[0];

// Handle "bye" keyword
if(response.equals("bye")) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(response.equals("bye")) {
if (response.equals("bye")) {

Copy link
Member

Choose a reason for hiding this comment

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

It is suggested to add a space after if.

break;
}

// Handle "list" keyword
else if(response.equals("list")) {
for (int i = 0; i < numTasks; i++) {
taskList[i].show();
}
}

else if(keyword.equals("mark")){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else if(keyword.equals("mark")){
} else if (keyword.equals("mark")) {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

// Check exception: number of words is not 2
if(words.length != 2){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(words.length != 2){
if (words.length != 2) {

Copy link
Member

Choose a reason for hiding this comment

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

It is suggested to add a space after if.

System.out.println("Please enter with correct format: mark [Integer]");
}
// Check exception: second word cannot be converted to integer or integer out of bounds
try{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try{
try {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

int markIndex = Integer.parseInt(words[1]);

if(markIndex < 1 || markIndex > numTasks){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try{
int markIndex = Integer.parseInt(words[1]);
if(markIndex < 1 || markIndex > numTasks){
try {
int markIndex = Integer.parseInt(words[1]);
if (markIndex < 1 || markIndex > numTasks) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.println("Please enter a positive integer less than or equal to current number of tasks (" + numTasks + ")");
continue;
}

taskList[markIndex - 1].mark();
}
catch(NumberFormatException e){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
catch(NumberFormatException e){
} catch (NumberFormatException e) {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write a try-catch statement like this.

System.out.println("Please enter with correct format: mark [Integer]");
}

Choose a reason for hiding this comment

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

Try to avoid deep nesting. Instead of deep nesting, you could break down your statements into additional methods.

}

else if(keyword.equals("unmark")){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else if(keyword.equals("unmark")){
} else if (keyword.equals("unmark")) {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

// Check exception: number of words is not 2
if(words.length != 2){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(words.length != 2){
if (words.length != 2) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.println("Please enter with correct format: unmark [Integer]");
}

// Check exception: second word cannot be converted to integer or integer out of bounds
try{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
try{
try {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

int markIndex = Integer.parseInt(words[1]);

if(markIndex < 1 || markIndex > numTasks){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(markIndex < 1 || markIndex > numTasks){
if (markIndex < 1 || markIndex > numTasks) {

Copy link
Member

Choose a reason for hiding this comment

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

It is suggested to add a space after if.

System.out.println("Please enter a positive integer less than or equal to current number of tasks (" + numTasks + ")");
continue;
}

taskList[markIndex - 1].unmark();
}
catch(NumberFormatException e){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
catch(NumberFormatException e){
} catch (NumberFormatException e){

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write a try-catch statement like this.

System.out.println("Please enter with correct format: unmark [Integer]");
}
}

else if(keyword.equals("todo")){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else if(keyword.equals("todo")){
} else if (keyword.equals("todo")) {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

String description = response.substring(5);
taskList[numTasks] = new ToDo(description);
numTasks++;

System.out.println("Created new ToDo:");
System.out.println(description);
}

else if(keyword.equals("deadline")){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else if(keyword.equals("deadline")){
} else if (keyword.equals("deadline")) {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

String description = response.substring(9);
System.out.println("Please enter the deadline:");
String deadline = scanner.nextLine();

taskList[numTasks] = new Deadline(description, deadline);
numTasks++;

System.out.println("Created new Deadline:");
System.out.println(description);
System.out.println("Due: " + deadline);
}

else if(keyword.equals("event")) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else if(keyword.equals("event")) {
} else if (keyword.equals("event")) {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

String description = response.substring(6);
System.out.println("Please enter event start period:");
String start = scanner.nextLine();
System.out.println("Please enter event end period:");
String end = scanner.nextLine();

taskList[numTasks] = new Event(description, start, end);
numTasks++;

System.out.println("Created new Event:");
System.out.println(description);
System.out.println("From: " + start);
System.out.println("To: " + end);
}

else{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else{
} else {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

System.out.println("Invalid keyword");
System.out.println("Valid keywords are: list, todo, deadline, event, mark, unmark, bye");
}

}

System.out.println("Bye. Hope to see you again soon!");
}
}
22 changes: 22 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Event extends Task{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class Event extends Task{
public class Event extends Task {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

private String start;
private String end;

public Event(String description, String start, String end){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public Event(String description, String start, String end){
public Event(String description, String start, String end) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

super(description);
this.start = start;
this.end = end;
}

@Override
public void show(){
System.out.print("[D][");
if(isDone){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void show(){
System.out.print("[D][");
if(isDone){
public void show() {
System.out.print("[D][");
if (isDone) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.print("X");
}
else{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else{
} else {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

System.out.print(" ");
}
System.out.println("] " + description + " (" + start + " to " + end + ")");
}
}
32 changes: 32 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Task{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class Task{
public class Task {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

protected String description;
protected boolean isDone;

public Task(String description){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public Task(String description){
public Task(String description) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

this.description = description;
isDone = false;
}

public void show(){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void show(){
public void show() {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.print("[?][");
if(isDone){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(isDone){
if (isDone) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.print("X");
}
else{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else{
} else {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

System.out.print(" ");
}
System.out.println("] " + description);
}

public void mark(){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void mark(){
public void mark() {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

isDone = true;
System.out.println("Marked as done:");
System.out.println(description);
}

public void unmark(){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void unmark(){
public void unmark() {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

isDone = false;
System.out.println("Marked as not done yet:");
System.out.println(description);
}
}
17 changes: 17 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class ToDo extends Task{
public ToDo(String description){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class ToDo extends Task{
public ToDo(String description){
public class ToDo extends Task {
public ToDo(String description) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

super(description);
}

@Override
public void show(){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void show(){
public void show() {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.print("[T][");
if(isDone){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(isDone){
if (isDone) {

Copy link
Member

Choose a reason for hiding this comment

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

Adding a space before the curly bracket is more consistent with our coding conventions.

System.out.print("X");
}
else{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
else{
} else {

Copy link
Member

Choose a reason for hiding this comment

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

According to our coding standards, it is recommended to write the else branch like this.

System.out.print(" ");
}
System.out.println("] " + description);
}
}