-
Notifications
You must be signed in to change notification settings - Fork 435
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
[Rena] iP #458
base: master
Are you sure you want to change the base?
[Rena] iP #458
Changes from 1 commit
55f9f9f
f837ddb
a6f7324
e038c80
ec99ab5
8bf1856
0b4044d
bfe14f0
beff8a4
3103d89
52770ed
e65d1c3
c9ede7f
7c7eb0f
a45e142
cecd03d
396cf5c
11e9506
f829900
89331f7
4459683
61137a6
eb8604d
c1110ed
e785e0e
fca0a8a
b21992a
1f9dfe6
96ec174
d8808e1
a7c37b3
ed78efc
1fa1a03
222176b
f075d9c
14682ee
0daaeec
a8872c7
774cdc7
b3794f2
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 | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||
import java.util.ArrayList; | ||||||
import java.util.Scanner; | ||||||
public class Duke { | ||||||
public static String printIntro() { | ||||||
|
@@ -17,12 +18,12 @@ public static String printOutro() { | |||||
"____________________________________________________________\n"; | ||||||
} | ||||||
|
||||||
public static String list(Task[] a, int counter) { | ||||||
public static String list(ArrayList<Task> a, int counter) { | ||||||
String x = ("Here are the tasks in your list: " + "\n" + | ||||||
"____________________________________________________________\n"); | ||||||
String result = ""; | ||||||
for (int i = 0; i < counter; i++) { | ||||||
result += (i + 1) + ". " + a[i].toString() + "\n"; | ||||||
result += (i + 1) + ". " + a.get(i).toString() + "\n"; | ||||||
} | ||||||
String y = ("____________________________________________________________\n"); | ||||||
return x + result + y; | ||||||
|
@@ -65,6 +66,18 @@ public static String getTime(String message) { | |||||
return time; | ||||||
} | ||||||
|
||||||
public static String deleteMessage(Task task, int count) { | ||||||
return "____________________________________________________________\n" + | ||||||
"Noted. I've removed this task:" + "\n" + task.toString() + "\n" + | ||||||
"Now you have " + count + " tasks in the list." + "\n" + | ||||||
"____________________________________________________________\n"; | ||||||
} | ||||||
|
||||||
public static ArrayList<Task> delete(ArrayList<Task> a, int count) { | ||||||
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 method name could be changed to explain more about what this method is deleting. |
||||||
a.remove(count); | ||||||
return a; | ||||||
} | ||||||
|
||||||
public static String replace(String message) { | ||||||
String newString = message.replaceAll("/(\\w+)", "$1:"); | ||||||
return newString; | ||||||
|
@@ -76,7 +89,7 @@ public static void main(String[] args) { | |||||
System.out.println("Enter Message"); | ||||||
|
||||||
final int ArraySize = 100; | ||||||
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. Constants should be in screaming_snake_case. |
||||||
Task[] tasks = new Task[ArraySize]; | ||||||
ArrayList<Task> tasks = new ArrayList<>(ArraySize); | ||||||
int counter = 0; | ||||||
|
||||||
while (true) { | ||||||
|
@@ -88,19 +101,22 @@ public static void main(String[] args) { | |||||
break; | ||||||
|
||||||
} else if (message.equals("list")) { | ||||||
System.out.println(list(tasks, counter)); | ||||||
System.out.println(list(tasks, tasks.size())); | ||||||
|
||||||
} else if (message.startsWith("mark") || message.startsWith("unmark")) { | ||||||
} else if (message.startsWith("mark") || message.startsWith("unmark") || message.startsWith("delete")) { | ||||||
String[] parts = message.split(" "); | ||||||
int num = Integer.parseInt(parts[1]); | ||||||
Task current = tasks[num - 1]; | ||||||
Task current = tasks.get(num - 1); | ||||||
|
||||||
if (message.startsWith("mark")) { | ||||||
current.markAsDone(); | ||||||
System.out.println(printMark(current)); | ||||||
} else { | ||||||
} else if (message.startsWith("unmark")){ | ||||||
current.unmark(); | ||||||
System.out.println(printMark(current)); | ||||||
}else{ | ||||||
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. I think you may have forgotten to add a space before and after the 'else' here. |
||||||
tasks.remove(num - 1); | ||||||
System.out.println(deleteMessage(current, tasks.size())); | ||||||
} | ||||||
} else if (message.equals("todo") || message.equals("deadline") || message.equals("event")){ | ||||||
throw new DukeExceptions("Don't forget the description !"); | ||||||
|
@@ -109,25 +125,28 @@ public static void main(String[] args) { | |||||
if (message.startsWith("todo")) { | ||||||
String[] parts = message.split(" ", 2); | ||||||
String task = parts[1]; | ||||||
tasks[counter] = new Todo(task); | ||||||
// tasks[counter] = new Todo(task); | ||||||
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. consider removing these comments once code is finalised :) |
||||||
tasks.add(new Todo(task)); | ||||||
counter++; | ||||||
System.out.println(added(tasks[counter - 1], counter)); | ||||||
System.out.println(added(tasks.get(counter - 1), counter)); | ||||||
} else if (message.startsWith("deadline")) { | ||||||
String task = getTask(message); | ||||||
String[] parts = time.split("by"); | ||||||
tasks[counter] = new Deadline(task, parts[1]); | ||||||
// tasks[counter] = new Deadline(task, parts[1]); | ||||||
tasks.add(new Deadline(task, parts[1]) ); | ||||||
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.
Suggested change
|
||||||
counter++; | ||||||
System.out.println(added(tasks[counter - 1], counter)); | ||||||
System.out.println(added(tasks.get(counter - 1), counter)); | ||||||
} else { | ||||||
String task = getTask(message); | ||||||
String[] parts = time.split("from"); | ||||||
String[] dateParts = parts[1].split("/to"); | ||||||
tasks[counter] = new Event(task, dateParts[0], dateParts[1]); | ||||||
// tasks[counter] = new Event(task, dateParts[0], dateParts[1]); | ||||||
tasks.add(new Event(task, dateParts[0], dateParts[1])); | ||||||
counter++; | ||||||
System.out.println(added(tasks[counter - 1], counter)); | ||||||
System.out.println(added(tasks.get(counter - 1), counter)); | ||||||
} | ||||||
|
||||||
}else { | ||||||
} else { | ||||||
throw new DukeExceptions("Sorry, I'm not sure what you mean"); | ||||||
} | ||||||
|
||||||
|
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.
Could probably store the lines as a constant value to make the code easier to change.