Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
817846f
level 0
lhlim88 Feb 8, 2025
c5fd455
level 1
lhlim88 Feb 8, 2025
50c81a9
level 2
lhlim88 Feb 15, 2025
4e9d824
level 3
lhlim88 Feb 27, 2025
340187b
level 4
lhlim88 Mar 1, 2025
b56022f
removing spaces in input
lhlim88 Mar 3, 2025
487f813
added exception for todo, deadline and event
lhlim88 Mar 3, 2025
ea54e99
added exception for mark, unmark & invalid input
lhlim88 Mar 3, 2025
278b61f
all exceptions added, level 5 complete
lhlim88 Mar 3, 2025
e440954
Merged Level-5 into master
lhlim88 Mar 3, 2025
073a202
added delete command
lhlim88 Mar 4, 2025
6da1f44
Merge branch-Level-6 into master
lhlim88 Mar 8, 2025
6973f03
Level 7
lhlim88 Mar 8, 2025
c1c2e94
Merge branch-Level-7 into master
lhlim88 Mar 8, 2025
59e4fd5
A-MoreOOP
lhlim88 Mar 9, 2025
e87ecaa
Level-9
lhlim88 Mar 9, 2025
d1b0245
solved error
lhlim88 Mar 9, 2025
17cf10a
resolve exception error
lhlim88 Mar 11, 2025
6eec05d
checked for code quality
lhlim88 Mar 12, 2025
65581d7
added javadoc comments
lhlim88 Mar 12, 2025
5151f5f
Update README.md
lhlim88 Mar 14, 2025
48fc7c4
Update README.md 2nd time
lhlim88 Mar 14, 2025
18c5c52
Update README.md 3rd time
lhlim88 Mar 14, 2025
169974a
Update README.md
lhlim88 Mar 14, 2025
ef36226
Update UG
lhlim88 Mar 14, 2025
19ff875
Update UG 2nd time
lhlim88 Mar 14, 2025
2d33c75
testing format for UG
lhlim88 Mar 14, 2025
db1c9b3
ensure correct format for UG
lhlim88 Mar 14, 2025
6651a07
UG formatting
lhlim88 Mar 14, 2025
1579be4
adjustments
lhlim88 Mar 14, 2025
ef38112
erge branch 'master' of https://github.com/limleyhooi/ip
lhlim88 Mar 14, 2025
16a4000
more edits
lhlim88 Mar 14, 2025
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
12 changes: 12 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Deadline extends Task{
protected String description;
protected String date;
public Deadline(String description, String date){
super(description);
this.date = date;
}
@Override
public String toString(){
return "[D]" + super.toString() + " (by: " + date + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

14 changes: 14 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Event extends Task{
protected String description;
protected String time1;
protected String time2;
public Event(String description, String time1, String time2){
super(description);
this.time1 = time1;
this.time2 = time2;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using a more descriptive name such as startTime, endTime instead of time1 and time2.

}
@Override
public String toString(){
return "[E]" + super.toString() + " (from: " + time1 + " to: " + time2 + ")";
}
}
144 changes: 144 additions & 0 deletions src/main/java/Rick.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import java.util.Scanner ;

public class Rick {
private static final String DIVIDER = " ____________________________________________________________";
private static void printDivider() {
System.out.println(DIVIDER);
}


public static void main(String[] args) {
String logo =
" ____ _ _ \n" +
"| _ \\(_) ___| | __\n" +
"| |_) | |/ __| |/ /\n" +
"| _ <| | (__| < \n" +
"|_| \\_\\_|\\___|_|\\_\\";
System.out.println("Hello from\n" + logo);
System.out.println("""
Hello, I'm rick (´。• ᵕ •。`)
What can I do for you?
""");
Scanner s = new Scanner(System.in);
Task[] tasks = new Task[100]; //create an Task array called tasks that hold 100 Task elements;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using a constant to avoid magic numbers

int i = 0;

while (true) {
System.out.print(">");
String input = s.nextLine(); //enter string element;
input = input.replaceAll("\\s","");//remove all spaces in user input.


if (input.startsWith("bye")) {
System.out.println("bye bye! Hope to see you soon (づ ̄ ³ ̄)づ");
break;
}
if (input.startsWith("list")){
if (i ==0) {
System.out.println(" No tasks added (;ↀ⌓ↀ)"); //tasks array is empty
} else {
System.out.println("Here are the items in your list ᕦ(ò_óˇ)ᕤ :");
for (int j = 0; j < i; j++) {
System.out.print(j + 1+"."); //iterate through tasks array;
System.out.println(tasks[j]);

}
}
continue;
}
if(input.startsWith("mark")){
int taskIndex = 0;//declare and initialise outside try-catch block;
try {
taskIndex = Integer.parseInt(input.substring(4)) - 1; //finding the index to mark;
if (taskIndex >= 0 && taskIndex < i) {
tasks[taskIndex].markAsDone();
printDivider();
System.out.println(" Nicee! I've marked this task as done ᕕ( ᐛ )ᕗ :");
System.out.println(tasks[taskIndex]);
printDivider();
} else {
System.out.println("Invalid task number!");
}
}catch(NumberFormatException e){
System.out.println("only a number after mark! O_o");
}
continue;
}
if(input.startsWith("unmark")){
int taskIndex = 0;
try {
taskIndex = Integer.parseInt(input.substring(6)) - 1;
if (taskIndex >= 0 && taskIndex < i) {
tasks[taskIndex].markAsUndone();
printDivider();
System.out.println(" Gotcha! I've unmarked this task (≧▽≦)");
System.out.println(tasks[taskIndex]);
printDivider();
} else {
System.out.println("Invalid task number!");
}
}catch(NumberFormatException e){
System.out.println("only a number after unmark! o_O");
}
continue;
}
if(input.startsWith("todo")){
input = input.substring(4);
try{
if(input.isEmpty()){
throw new RickException();
}}catch(RickException e){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
try{
if(input.isEmpty()){
throw new RickException();
}}catch(RickException e){
try {
if (input.isEmpty()) {
throw new RickException();
}
} catch (RickException e) {

Consider following the coding standard as shown above to maintain consistency and readability throughout your code.

System.out.println("Your todo task needs a description with keyword: todo"+ System.lineSeparator()+"E.g. todo borrow books");
continue;
}
tasks[i] = new Todo(input);
}
if(input.startsWith("deadline")){
String modifiedInput = input.substring(8);//remove the word deadline;
try{
if(modifiedInput.isEmpty()){
throw new RickException();
}}catch(RickException e){
System.out.println("Your deadline task needs a description with keywords: deadline, /by" + System.lineSeparator()+" E.g. deadline return book /by sunday ");
continue;
}
String[] part = modifiedInput.split("/by",2); //split modified string to description and date;
String Deadline_description = part[0].trim();
String Deadline_date = part[1].trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Variable names must be in camelCase

tasks[i] = new Deadline(Deadline_description,Deadline_date);


}
if(input.startsWith("event")){
String modifiedInput = input.substring(5);
try{
if(modifiedInput.isEmpty()){
throw new RickException();
}}catch(RickException e) {
System.out.println(" Your event task needs a description with keywords: event, /from & /to" +System.lineSeparator()+"E.g. event project meeting /from Mon 2pm /to 4pm ");
continue;
}
String[] part = modifiedInput.split("/from|/to", 3);
String description = part[0].trim();
String time1 = part[1].trim();
String time2 = part[2].trim();
int eventIndex = i + 1;
tasks[i] = new Event(description, time1, time2);


}
if(tasks[i] ==null){
System.out.println("sorry pal, not a recognized command ಸ‿ಸ ");
continue;
}

System.out.println("Okie doki, added to task! ʕ•ᴥ•ʔ ");
System.out.println(tasks[i]);
System.out.println("Now you have "+ String.valueOf(i + 1)+ " tasks in list ᕙ(⇀‸↼‶)ᕗ");
i++;


}
}

}
3 changes: 3 additions & 0 deletions src/main/java/RickException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class RickException extends Exception{
//empty;
}
25 changes: 25 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

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

public void markAsDone(){
this.isDone = true;
}

public void markAsUndone(){
this.isDone = false;
}
@Override
public String toString(){
return "[" + getStatusIcon() +"] " + description;
}
}
9 changes: 9 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Todo extends Task{
public Todo(String description){
super(description);
}
@Override
public String toString(){
return "[T]" + super.toString();
}
}