Skip to content

[Li Xinyi] iP#98

Open
LI-XINYI1 wants to merge 35 commits into
nus-cs2113-AY2122S2:masterfrom
LI-XINYI1:master
Open

[Li Xinyi] iP#98
LI-XINYI1 wants to merge 35 commits into
nus-cs2113-AY2122S2:masterfrom
LI-XINYI1:master

Conversation

@LI-XINYI1

Copy link
Copy Markdown

No description provided.

Comment thread src/main/java/TaskManager.java Outdated
public TaskManager() {
}

public void welcome() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps change your method name to an action, like printWelcome()

Comment thread src/main/java/Baymax.java Outdated
Comment on lines +8 to +114
public static void main(String[] args) throws IOException {

Scanner in = new Scanner(System.in);
String command;
String taskDescrip;
String[] taskWord;
TaskManager tManager = new TaskManager();
String horiLine = "____________________________________________________________\n";

//load record
try {
tManager.initialiseNewFile();
} catch (FileNotFoundException e) {
System.out.println("File not found.");
} catch (IOException e) {
e.printStackTrace();
}

tManager.welcome(); //greating

command = in.nextLine();
while (!command.equals("bye")) {

String[] word_split;
word_split = command.split(" ", 2);
String taskName = word_split[0];

//different functions based on command lines
switch (taskName) {
case "todo":
tManager.addTask(new Todo(word_split[1]));
break;
case "deadline":
try {
taskWord = word_split[1].split("/by ", 2);
taskDescrip = taskWord[0];
String ddl = taskWord[1];
tManager.addTask(new Deadline(taskDescrip, ddl));
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(" ☹ OOPS!!! The description of a deadline cannot be empty.");
} catch (BaymaxException b){
System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again.");
}
break;
case "event":
try {
taskWord = word_split[1].split("/at ", 2);
taskDescrip = taskWord[0];
String eventTime = taskWord[1];
tManager.addTask(new Event(taskDescrip, eventTime));
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(" ☹ OOPS!!! The description of an event cannot be empty.");
} catch (BaymaxException b){
System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again.");
}
break;
case "list":
tManager.printTaskList();
break;
case "mark":
System.out.println(horiLine);
try {
tManager.markTask(Integer.parseInt(word_split[1]) - 1);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Please input an integer for task index.");
} catch (BaymaxException b){
System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again.");
}
System.out.println(horiLine);
break;
case "unmark":
System.out.println(horiLine);
try {
tManager.unmarkTask(Integer.parseInt(word_split[1]) - 1);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Please input an integer for task index.");
} catch (BaymaxException b){
System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again.");
}
System.out.println(horiLine);
break;
case "delete":
System.out.println(horiLine);
try {
tManager.deleteTask(Integer.parseInt(word_split[1]) - 1);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Please input an integer for task index.");
} catch (BaymaxException b){
System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again.");
}
//check branch merge
System.out.println(horiLine);
break;
default:
System.out.println(horiLine);
System.out.println("Error. Please retry");
System.out.println(horiLine);
break;
}
command = in.nextLine();

}
tManager.saveTask();
tManager.bye(); //bye
}

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to SLAP your method here as it is too long

Comment thread src/main/java/TaskManager.java Outdated
Comment on lines +78 to +88
if(!dir.exists()){
dir.mkdir();
System.out.println("create a new directory \"data\"...... ");
}
File file = new File("data/Baymax.txt");
if(!file.exists()) {
file.createNewFile();
System.out.println("create a new file \"Baymax.txt\"...... ");
System.out.println(horiLine);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Be sure to add spaces after your if statements (i.e. if (!dir.exists()) {)

Comment thread src/main/java/TaskManager.java Outdated

public void saveTask() throws IOException {

FileWriter fw = new FileWriter("data/Baymax.txt");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Magic literal here, try to declare it as a static constant above.

Comment thread src/main/java/Baymax.java Outdated
Comment on lines +69 to +75
try {
tManager.markTask(Integer.parseInt(word_split[1]) - 1);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Please input an integer for task index.");
} catch (BaymaxException b){
System.out.println( b.getMessage() +" ☹ OOPS!!! Let's do it again.");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe this would cause an error if you type in any non-numeric input for your second option. mark abc would throw a NumberFormatException if not handled correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants