Skip to content

Commit 8b06d55

Browse files
authored
Merge pull request #5 from leowyh/master
Applied A-Checkstyle to code after merging with Jiayu's code
2 parents 095ce0a + eeccd89 commit 8b06d55

File tree

11 files changed

+131
-141
lines changed

11 files changed

+131
-141
lines changed

src/main/java/Duke.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author Leow Yong Heng
1414
*/
1515

16-
public class Duke{
16+
public class Duke {
1717
private static Ui ui;
1818
private static TaskList tasklist;
1919
private static Storage storage;
@@ -22,7 +22,7 @@ public class Duke{
2222
* Creates a Duke instance and initialises the required attributes.
2323
* @param filepath Filepath to the storage.
2424
*/
25-
private Duke(String filepath){
25+
private Duke(String filepath) {
2626
ui = new Ui();
2727
storage = new Storage(filepath);
2828
ArrayList<Task> arraylist = storage.load();
@@ -32,12 +32,12 @@ private Duke(String filepath){
3232
/**
3333
* Method to run the Duke instance and take in the inputs of the user.
3434
*/
35-
private void run(){
36-
ui.StartMessage();
35+
private void run() {
36+
ui.startMessage();
3737

3838
boolean isExit = false;
39-
while(!isExit){
40-
String input = ui.readinput();
39+
while (!isExit) {
40+
String input = ui.readInput();
4141
isExit = Parser.parse(input, tasklist, ui, storage);
4242
}
4343
}
@@ -46,7 +46,7 @@ private void run(){
4646
* The main method of the Duke program, which instantiates a duke instance with the filepath to the storage.
4747
* @param args Unused.
4848
*/
49-
public static void main(String[] args){
49+
public static void main(String[] args) {
5050
new Duke("data/duke.txt").run();
5151
}
5252
}

src/main/java/command/Parser.java

+72-79
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,47 @@ public class Parser {
2828
* @return Returns boolean variable to indicate when to stop parsing for input.
2929
* @throws DukeException if input is not valid.
3030
*/
31-
public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage){
31+
public static boolean parse(String input, TaskList tasklist, Ui ui, Storage storage) {
3232
try {
33-
if (IsBye(input)) {
33+
if (isBye(input)) {
3434
//print bye message
35-
ui.ByeMessage();
35+
ui.byeMessage();
3636
ui.getIn().close();
3737
return true;
3838

39-
} else if (IsList(input)) {
39+
} else if (isList(input)) {
4040
//print out current list
41-
ui.PrintList(tasklist, "list");
41+
ui.printList(tasklist, "list");
4242

43-
} else if (IsDone(input)) {
44-
ProcessDone(input, tasklist, ui);
43+
} else if (isDone(input)) {
44+
processDone(input, tasklist, ui);
4545

46-
} else if (IsDeadline(input)) {
47-
ProcessDeadline(input, tasklist, ui);
48-
storage.save(tasklist.ReturnArrayList());
46+
} else if (isDeadline(input)) {
47+
processDeadline(input, tasklist, ui);
48+
storage.save(tasklist.returnArrayList());
4949

50-
} else if (IsTodo(input)) {
51-
ProcessTodo(input, tasklist, ui);
52-
storage.save(tasklist.ReturnArrayList());
50+
} else if (isTodo(input)) {
51+
processTodo(input, tasklist, ui);
52+
storage.save(tasklist.returnArrayList());
5353

54-
} else if (IsEvent(input)) {
55-
ProcessEvent(input, tasklist, ui);
56-
storage.save(tasklist.ReturnArrayList());
54+
} else if (isEvent(input)) {
55+
processEvent(input, tasklist, ui);
56+
storage.save(tasklist.returnArrayList());
5757

58-
} else if (IsDelete(input)) {
59-
ProcessDelete(input, tasklist, ui);
60-
storage.save(tasklist.ReturnArrayList());
58+
} else if (isDelete(input)) {
59+
processDelete(input, tasklist, ui);
60+
storage.save(tasklist.returnArrayList());
6161

62-
} else if (IsFind(input)) {
63-
ProcessFind(input, tasklist, ui);
62+
} else if (isFind(input)) {
63+
processFind(input, tasklist, ui);
6464

6565
} else {
66-
throw new DukeException(" \u2639 OOPS!!! I'm sorry, but I don't know what that means :-(");
66+
throw new DukeException(" OOPS!!! I'm sorry, but I don't know what that means :-(");
6767

6868
}
6969

70-
}
71-
catch (DukeException e){
72-
ui.ExceptionMessage(e.getMessage());
70+
} catch (DukeException e) {
71+
ui.exceptionMessage(e.getMessage());
7372
return true;
7473
}
7574

@@ -82,19 +81,18 @@ public static boolean parse(String input, TaskList tasklist, Ui ui, Storage stor
8281
* @param tasklist Tasklist of the user.
8382
* @param ui Ui that interacts with the user.
8483
*/
85-
private static void ProcessFind(String input, TaskList tasklist, Ui ui){
86-
try{
84+
private static void processFind(String input, TaskList tasklist, Ui ui) {
85+
try {
8786
TaskList findlist = new TaskList();
8887
String[] splitspace = input.split(" ", 2);
89-
for (Task tasks : tasklist.ReturnArrayList()){
90-
if(tasks.getDescription().contains(splitspace[1])){
91-
findlist.AddTask(tasks);
88+
for (Task tasks : tasklist.returnArrayList()) {
89+
if (tasks.getDescription().contains(splitspace[1])) {
90+
findlist.addTask(tasks);
9291
}
9392
}
94-
ui.PrintList(findlist, "find");
95-
}
96-
catch(ArrayIndexOutOfBoundsException e) {
97-
ui.ExceptionMessage(" \u2639 OOPS!!! The content to find cannot be empty.");
93+
ui.printList(findlist, "find");
94+
} catch (ArrayIndexOutOfBoundsException e) {
95+
ui.exceptionMessage(" ☹ OOPS!!! The content to find cannot be empty.");
9896
}
9997
}
10098

@@ -104,16 +102,16 @@ private static void ProcessFind(String input, TaskList tasklist, Ui ui){
104102
* @param tasklist Tasklist of the user.
105103
* @param ui Ui that interacts with the user.
106104
*/
107-
private static void ProcessDelete(String input, TaskList tasklist, Ui ui){
108-
try{
105+
private static void processDelete(String input, TaskList tasklist, Ui ui) {
106+
try {
109107
String[] arr = input.split(" ", 2);
110108
int numdelete = Integer.parseInt(arr[1]) - 1;
111-
String task = tasklist.get(numdelete).GiveTask();
112-
tasklist.DeleteTask(numdelete);
113-
ui.PrintDeleteMessage(task, tasklist);
109+
String task = tasklist.get(numdelete).giveTask();
110+
tasklist.deleteTask(numdelete);
111+
ui.printDeleteMessage(task, tasklist);
114112

115-
}catch(ArrayIndexOutOfBoundsException e){
116-
ui.ExceptionMessage(" \u2639 OOPS!!! Please input the list number to delete.");
113+
} catch (ArrayIndexOutOfBoundsException e) {
114+
ui.exceptionMessage(" OOPS!!! Please input the list number to delete.");
117115
}
118116
}
119117

@@ -123,15 +121,15 @@ private static void ProcessDelete(String input, TaskList tasklist, Ui ui){
123121
* @param tasklist Tasklist of the user.
124122
* @param ui Ui that interacts with the user.
125123
*/
126-
private static void ProcessDone(String input, TaskList tasklist, Ui ui){
127-
try{
124+
private static void processDone(String input, TaskList tasklist, Ui ui) {
125+
try {
128126
String[] arr = input.split(" ", 2);
129127
int numdone = Integer.parseInt(arr[1]) - 1;
130-
tasklist.get(numdone).SetDone();
131-
ui.PrintDoneMessage(numdone, tasklist);
128+
tasklist.get(numdone).setDone();
129+
ui.printDoneMessage(numdone, tasklist);
132130

133-
}catch(ArrayIndexOutOfBoundsException e){
134-
ui.ExceptionMessage(" \u2639 OOPS!!! Please input the list number to indicate as done.");
131+
} catch (ArrayIndexOutOfBoundsException e) {
132+
ui.exceptionMessage(" OOPS!!! Please input the list number to indicate as done.");
135133
}
136134
}
137135

@@ -141,7 +139,7 @@ private static void ProcessDone(String input, TaskList tasklist, Ui ui){
141139
* @param tasklist Tasklist of the user.
142140
* @param ui Ui that interacts with the user.
143141
*/
144-
private static void ProcessDeadline(String input, TaskList tasklist, Ui ui){
142+
private static void processDeadline(String input, TaskList tasklist, Ui ui) {
145143
try {
146144
String[] splitspace = input.split(" ", 2);
147145
String[] splitslash = splitspace[1].split("/", 2);
@@ -150,14 +148,12 @@ private static void ProcessDeadline(String input, TaskList tasklist, Ui ui){
150148
String taskTime = splittime[1];
151149
Date formattedtime = dataformat.parse(taskTime);
152150
Deadline deadline = new Deadline(taskDescription, dataformat.format(formattedtime));
153-
tasklist.AddTask(deadline);
154-
ui.PrintAddedMessage(deadline, tasklist);
155-
}
156-
catch (ArrayIndexOutOfBoundsException e){
157-
ui.ExceptionMessage(" \u2639 OOPS!!! The description of a deadline cannot be empty.");
158-
}
159-
catch (ParseException e){
160-
ui.ExceptionMessage(" \u2639 OOPS!!! Format of time is wrong.");
151+
tasklist.addTask(deadline);
152+
ui.printAddedMessage(deadline, tasklist);
153+
} catch (ArrayIndexOutOfBoundsException e) {
154+
ui.exceptionMessage(" ☹ OOPS!!! The description of a deadline cannot be empty.");
155+
} catch (ParseException e) {
156+
ui.exceptionMessage(" ☹ OOPS!!! Format of time is wrong.");
161157
}
162158
}
163159

@@ -167,15 +163,14 @@ private static void ProcessDeadline(String input, TaskList tasklist, Ui ui){
167163
* @param tasklist Tasklist of the user.
168164
* @param ui Ui that interacts with the user.
169165
*/
170-
private static void ProcessTodo(String input, TaskList tasklist, Ui ui){
166+
private static void processTodo(String input, TaskList tasklist, Ui ui) {
171167
try {
172168
String[] splitspace = input.split(" ", 2);
173169
Todo todotoadd = new Todo(splitspace[1]);
174-
tasklist.AddTask(todotoadd);
175-
ui.PrintAddedMessage(todotoadd, tasklist);
176-
}
177-
catch (ArrayIndexOutOfBoundsException e) {
178-
ui.ExceptionMessage(" \u2639 OOPS!!! The description of a todo cannot be empty.");
170+
tasklist.addTask(todotoadd);
171+
ui.printAddedMessage(todotoadd, tasklist);
172+
} catch (ArrayIndexOutOfBoundsException e) {
173+
ui.exceptionMessage(" ☹ OOPS!!! The description of a todo cannot be empty.");
179174
}
180175
}
181176

@@ -185,7 +180,7 @@ private static void ProcessTodo(String input, TaskList tasklist, Ui ui){
185180
* @param tasklist Tasklist of the user.
186181
* @param ui Ui that interacts with the user.
187182
*/
188-
private static void ProcessEvent(String input, TaskList tasklist, Ui ui){
183+
private static void processEvent(String input, TaskList tasklist, Ui ui) {
189184
try {
190185
String[] splitspace = input.split(" ", 2);
191186
String[] splitslash = splitspace[1].split("/", 2);
@@ -194,47 +189,45 @@ private static void ProcessEvent(String input, TaskList tasklist, Ui ui){
194189
String taskTime = splittime[1];
195190
Date formattedtime = dataformat.parse(taskTime);
196191
Event event = new Event(taskDescription, dataformat.format(formattedtime));
197-
tasklist.AddTask(event);
198-
ui.PrintAddedMessage(event, tasklist);
199-
}
200-
catch(ArrayIndexOutOfBoundsException e) {
201-
ui.ExceptionMessage(" \u2639 OOPS!!! The description of a event cannot be empty.");
202-
}
203-
catch (ParseException e){
204-
ui.ExceptionMessage(" \u2639 OOPS!!! Format of time is wrong.");
192+
tasklist.addTask(event);
193+
ui.printAddedMessage(event, tasklist);
194+
} catch (ArrayIndexOutOfBoundsException e) {
195+
ui.exceptionMessage(" ☹ OOPS!!! The description of a event cannot be empty.");
196+
} catch (ParseException e) {
197+
ui.exceptionMessage(" ☹ OOPS!!! Format of time is wrong.");
205198
}
206199
}
207200

208201

209-
private static boolean IsBye(String input){
202+
private static boolean isBye(String input) {
210203
return input.equals("bye");
211204
}
212205

213-
private static boolean IsList(String input){
206+
private static boolean isList(String input) {
214207
return input.equals("list");
215208
}
216209

217-
private static boolean IsDone(String input){
210+
private static boolean isDone(String input) {
218211
return input.startsWith("done");
219212
}
220213

221-
private static boolean IsDeadline(String input){
214+
private static boolean isDeadline(String input) {
222215
return input.startsWith("deadline");
223216
}
224217

225-
private static boolean IsTodo(String input){
218+
private static boolean isTodo(String input) {
226219
return input.startsWith("todo");
227220
}
228221

229-
private static boolean IsEvent(String input){
222+
private static boolean isEvent(String input) {
230223
return input.startsWith("event");
231224
}
232225

233-
private static boolean IsDelete(String input){
226+
private static boolean isDelete(String input) {
234227
return input.startsWith("delete");
235228
}
236229

237-
private static boolean IsFind(String input){
230+
private static boolean isFind(String input) {
238231
return input.startsWith("find");
239232
}
240233
}

src/main/java/command/Storage.java

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
package command;
22

3-
import task.Task;
3+
import java.io.ObjectOutputStream;
4+
import java.io.FileOutputStream;
5+
import java.io.EOFException;
6+
import java.io.FileInputStream;
7+
import java.io.IOException;
8+
import java.io.ObjectInputStream;
49

5-
import java.io.*;
10+
import task.Task;
611
import java.util.ArrayList;
712

813
/**
914
* Storage that saves and loads the tasklist of the user.
1015
*/
11-
public class Storage{
16+
public class Storage {
1217
private static String filepath;
1318

1419
/**
1520
* Creates a Storage instance with the required attributes.
1621
* @param filepath Filepath to the storage file.
1722
*/
18-
public Storage(String filepath){
23+
public Storage(String filepath) {
1924
Storage.filepath = filepath;
2025
}
2126

2227
/**
2328
* Loads an ArrayList containing the Task object from the storage file.
2429
* @return The ArrayList containing the Task object.
2530
*/
26-
public static ArrayList<Task> load(){
27-
try
28-
{
29-
31+
public static ArrayList<Task> load() {
32+
try {
3033

3134
FileInputStream file = new FileInputStream(filepath);
3235
ObjectInputStream out = new ObjectInputStream(file);
@@ -37,17 +40,11 @@ public static ArrayList<Task> load(){
3740
file.close();
3841

3942
return arraylist;
40-
}
41-
catch (EOFException e) {
43+
} catch (EOFException e) {
4244
System.out.println("File is empty");
43-
44-
}
45-
catch (IOException ioe)
46-
{
45+
} catch (IOException ioe) {
4746
ioe.printStackTrace();
48-
}
49-
catch (ClassNotFoundException c)
50-
{
47+
} catch (ClassNotFoundException c) {
5148
System.out.println("Class not found");
5249
c.printStackTrace();
5350
}
@@ -58,7 +55,7 @@ public static ArrayList<Task> load(){
5855
* Saves the tasklist of the user as an ArrayList containing the task object.
5956
* @param tasklist Tasklist of the user.
6057
*/
61-
public static void save(ArrayList<Task> tasklist){
58+
public static void save(ArrayList<Task> tasklist) {
6259
try {
6360
FileOutputStream file = new FileOutputStream(filepath);
6461
ObjectOutputStream out = new ObjectOutputStream(file);

0 commit comments

Comments
 (0)