Skip to content

Commit

Permalink
Resolve merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinSekYi committed Sep 12, 2024
2 parents f988579 + af7643f commit 64caf74
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 118 deletions.
107 changes: 1 addition & 106 deletions src/main/java/carly/Carly.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package carly;

import java.io.IOException;
import java.util.Scanner;

import carly.exception.CarlyException;
import carly.ui.Ui;
Expand Down Expand Up @@ -103,115 +102,11 @@ public String getResponse(String input) {
response = e.getMessage();
}

assert !response.isEmpty() : "Response must not be empty";
return response;
}

/**
* Initiates a conversation with the user. Can use commands to do various tasks.
* The conversation continues until the user inputs the "BYE" command.
*
* If the user enters an invalid command or provides insufficient information
* appropriate exceptions are caught, and error messages are displayed without terminating the chat.
*/
private void chat() {
Scanner scan = new Scanner(System.in);
Ui ui = new Ui();
ui = ui.setUsername(scan);
ui.welcomeMsg();

String input;
String taskDescription;
Parser.Command command;
Storage listStorage = new Storage("./data/CarlyList.txt");

while (true) {
try {
input = ui.readInput(scan);
Parser parser = new Parser(input);
command = parser.getCommand();
taskDescription = parser.getDetailsAfterCommand(command);
} catch (CarlyException e) {
System.out.println(e.getMessage());
continue;
}

switch (command) {
case BYE:
ui.byeMsg();
return;
case LIST:
this.taskList.printTaskList();
break;
case MARK:
try {
this.taskList.mark(taskDescription);
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
case UNMARK:
try {
this.taskList.unmark(taskDescription);
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
case DELETE:
try {
this.taskList.delete(taskDescription);
break;
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
case FIND:
try {
this.taskList.find(taskDescription);
break;
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
case TODO:
try {
this.taskList.addToDo(taskDescription);
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
case DEADLINE:
try {
this.taskList.addDeadLine(taskDescription);
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
case EVENT:
try {
this.taskList.addEvent(taskDescription);
} catch (CarlyException e) {
System.out.println(e.getMessage());
}
break;
default:
Ui.printOutput("Oops, please print a valid command! ");
}
try {
listStorage.savesFile(this.taskList);
} catch (IOException | CarlyException e) {
System.out.println(e.getMessage());
}
}
}

/** Creates a new instance of the Carly chatbot and starts the chat session. */
public static void main(String[] args) {
Carly carly = new Carly();
try {
carly.chat();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

9 changes: 0 additions & 9 deletions src/main/java/carly/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ public String byeMsg() {
return ("Bye " + username + ". I'll see you next time!");
}

/** Reads input when user types into the chatbot. */
public String readInput(Scanner scan) throws CarlyException {
if (scan.hasNextLine()) {
return scan.nextLine();
} else {
throw new CarlyException("");
}
}

public static void printOutput(String message) {
System.out.println(INDENTATION + message);
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/carly/utils/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public String find(String word) throws CarlyException {
public String addToDo(String taskDescription) throws CarlyException {
Todo t = new Todo(taskDescription);
this.taskList.add(t);
assert this.getSize() > 0 : "Task list should have at least one task after adding";
return "Got it. I've added this task:\n" + TWO_INDENT + t;
}

Expand All @@ -132,6 +133,7 @@ public String addDeadLine(String taskDescription) throws CarlyException {

Deadline t = new Deadline(task, dueDate);
this.taskList.add(t);
assert this.getSize() > 0 : "Task list should have at least one task after adding";
return "Got it. I've added this task:\n" + TWO_INDENT + t;
} catch (ArrayIndexOutOfBoundsException e) {
throw new CarlyMissingDateTimeException("task description or \"/by\" command");
Expand All @@ -155,6 +157,7 @@ public String addEvent(String taskDescription) throws CarlyMissingDateTimeExcept

Event t = new Event(task, startTime, endTime);
this.taskList.add(t);
assert this.getSize() > 0 : "Task list should have at least one task after adding";
String msg = "Got it. I've added this task:\n" + TWO_INDENT + t;
return msg + "\n" + taskListSize();
} catch (ArrayIndexOutOfBoundsException e) {
Expand All @@ -177,7 +180,7 @@ public String taskListSize() {
return ONE_INDENT + "Now you have " + this.getSize() + " tasks in the list.";
}

/** Prints list for Command FIND*/
/** Prints list for Command FIND. */
public String printTaskList(String msg) {
StringBuilder sb = new StringBuilder();

Expand All @@ -192,8 +195,7 @@ public String printTaskList(String msg) {
return sb.toString();
}


/** Prints list for Command LIST*/
/** Prints list for Command LIST. */
public String printTaskList() {
if (this.taskList.isEmpty()) {
return "There's nothing in your list yet.";
Expand Down

0 comments on commit 64caf74

Please sign in to comment.