Skip to content

Commit

Permalink
Update JavaDoc
Browse files Browse the repository at this point in the history
Update readme
  • Loading branch information
bnjm2000 committed Oct 6, 2023
1 parent 30d61b4 commit 304dedc
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 233 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ Chatty is a CLI chatbot designed to help you manage your daily tasks and deadlin
## Quick Start
1. Ensure you have Java 11 or above installed on your computer.
- [How to Check Your Java Version](https://www.java.com/en/download/help/version_manual.html)
2. Upon successful launch of the chatbot, it would display:
2. Move the downloaded Chatty v.X.jar file into a folder on its own.
3. To run Chatty, simply open `terminal` or `command prompt` and type the following:
```
java -jar {filename}.jar
```
where {filename} includes the path to Chatty.jar.


4. Upon successful launch of the chatbot, it would display:
```
____________________________________________________________
Hello! I'm Chatty!
Expand Down
Empty file added chatty.txt
Empty file.
224 changes: 0 additions & 224 deletions src/main/java/Chatty/Chatty.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class Chatty {
private Storage storage;
private TaskList tasks;
private Ui ui;
//private static final String FILE_PATH = "./data/chatty.txt";
//public static final String LINE = "____________________________________________________________";
public Chatty (String filePath){
ui = new Ui();
storage = new Storage(filePath);
Expand All @@ -23,7 +21,6 @@ public Chatty (String filePath){
}
public void run() {
ui.printWelcomeMessage();
boolean isExit = false;
String fullCommand = ui.getUserInput();
while (!fullCommand.equalsIgnoreCase("bye")) {
try {
Expand All @@ -43,226 +40,5 @@ public void run() {

public static void main(String[] args) {
new Chatty("./data/chatty.txt").run();
// ArrayList<Task> tasks = new ArrayList<>();
// int taskCount = 0;
// taskCount = loadTasks(tasks, taskCount);
// printWelcomeMessage();
// Scanner scanner = new Scanner(System.in);
// String input = scanner.nextLine();
// int index;
// loop:
// while (!input.equalsIgnoreCase("bye")) {
// String[] words = input.split(" ");
// String command = words[0].toLowerCase();
// switch (command) {
// case "list":
// listAllTasks(taskCount, tasks);
// input = scanner.nextLine();
// continue loop;
// case "mark":
// mark(input, tasks);
// break;
// case "unmark":
// unmark(input, tasks);
// break;
// case "todo":
// taskCount = createTodo(input, tasks, taskCount);
// break;
// case "deadline":
// taskCount = createDeadline(input, tasks, taskCount);
// break;
// case "event":
// taskCount = createEvent(input, tasks, taskCount);
// break;
// case "delete":
// taskCount = deleteEvent(input, taskCount, tasks);
// break;
// default:
// System.out.println(LINE);
// System.out.println("Unknown command. Please try again or type \"help\"");
// System.out.println(LINE);
// input = scanner.nextLine();
// continue loop;
// }
// System.out.println("Now you have " + taskCount + " tasks in the list.");
// System.out.println(LINE);
// input = scanner.nextLine();
// }
// System.out.println(LINE);
// saveTasks(tasks, taskCount);
// System.out.println("Bye. Hope to see you again soon!");
// System.out.println(LINE);
// scanner.close();
}

// private static int deleteEvent(String input, int taskCount, ArrayList<Task> tasks) {
// int taskIndexToDelete = Integer.parseInt(input.substring(7)) - 1;
// if (taskIndexToDelete >= 0 && taskIndexToDelete < tasks.size()) {
// Task deletedTask = tasks.get(taskIndexToDelete);
// taskCount--;
// System.out.println("Noted. I've removed this task:");
// System.out.println(deletedTask.getDescription());
// } else {
// System.out.println("☹ OOPS!!! Invalid task number to delete.");
// }
// return taskCount;
// }
//
// private static int loadTasks(ArrayList<Task> tasks, int taskCount) {
// try {
// System.out.println(FILE_PATH);
// File file = new File(FILE_PATH);
// if (!file.exists()){
// System.out.println("Making new file...");
// boolean isFileCreated = file.createNewFile();
// return taskCount;
// //System.out.println("New file made." + file.getAbsolutePath());
// }
// Scanner scanner = new Scanner(file);
// while (scanner.hasNextLine()) {
// String line = scanner.nextLine();
// String[] parts = line.split("\\|");
//
// String type = parts[0].trim();
// boolean isDone = parts[1].trim().equals("1");
// String description = parts[2].trim();
//
// switch (type) {
// case "T":
// tasks.add(new Todo(description));
// break;
// case "D":
// String by = parts[3].trim();
// tasks.add(new Deadline(description, by));
// break;
// case "E":
// String fromTo = parts[3].trim();
// String[] fromToParts = fromTo.split(" to ");
// String from = fromToParts[0].trim();
// String to = fromToParts[1].trim();
// tasks.add(new Event(description, from, to));
// break;
// default:
// throw new IOException("Invalid data in file: Unknown task type.");
// }
//
// tasks.get(taskCount).setIsDone(isDone);
// taskCount++;
// }
// scanner.close();
// } catch (IOException e) {
// System.out.println("Error loading or creating data file.");
// }
// return taskCount;
// }
//
//
// private static void saveTasks(ArrayList<Task> tasks, int taskCount) {
// try {
// FileWriter writer = new FileWriter(FILE_PATH);
// for (int i = 0; i < taskCount; i++) {
// writer.write(tasks.get(i).saveFormat() + "\n");
// }
// writer.close();
// } catch (IOException e) {
// System.err.println("Error saving data file: " + e.getMessage());
// }
// }
//
// private static void listAllTasks(int taskCount, ArrayList<Task> tasks) {
// System.out.println(LINE);
// System.out.println("Here are the tasks in your list:");
// for (int i = 0; i < taskCount; i++) {
// System.out.println((i + 1) + ". " + tasks.get(i).getDescription());
// }
// System.out.println(LINE);
// }
//
// private static void mark(String input, ArrayList<Task> tasks) {
// int index;
// index = Integer.parseInt(input.substring(5)) - 1;
// tasks.get(index).mark();
// System.out.println(LINE);
// System.out.println("Nice! I've marked this task as done:");
// System.out.println(tasks.get(index).getDescription());
// }
//
// private static void unmark(String input, ArrayList<Task> tasks) {
// int index;
// index = Integer.parseInt(input.substring(7)) - 1;
// tasks.get(index).unmark();
// System.out.println(LINE);
// System.out.println("OK, I've marked this task as not done yet:");
// System.out.println(tasks.get(index).getDescription());
// }
//
// private static int createTodo(String input, ArrayList<Task> tasks, int taskCount) {
// if (input.length() > 5) {
// String todoDescription = input.substring(5);
// tasks.add(new Todo(todoDescription));
// taskCount++;
// System.out.println("Got it. I've added this task:");
// System.out.println("[T][ ] " + todoDescription);
// } else {
// System.out.println(LINE + "\n☹ OOPS!!! The description of a todo cannot be empty.");
// }
// return taskCount;
// }
//
// private static int createDeadline(String input, ArrayList<Task> tasks, int taskCount) {
// int byIndex = input.indexOf("/by");
// //System.out.println(byIndex);
// if (byIndex != -1 && input.length() > 9 && byIndex != 9) {
// String deadlineDescription = input.substring(9, byIndex).trim();
// String by = input.substring(byIndex + 3).trim();
// tasks.add(new Deadline(deadlineDescription, by));
// taskCount++;
// System.out.println("Got it. I've added this task:");
// System.out.println("[D][ ] " + deadlineDescription + " (by: " + by + ")");
// } else if (byIndex == -1) {
// System.out.println(LINE + "\n☹ OOPS!!! Invalid Deadline format. Please use /by to specify a deadline.");
// System.out.println("E.g. deadline homework /by 20 Aug");
// } else if (byIndex == 9 || input.length() <= 9) {
// System.out.println(LINE + "\n☹ OOPS!!! Description of Deadline task needed!");
// System.out.println("E.g. deadline homework /by 20 Aug");
// } else {
// System.out.println(LINE + "\n☹ OOPS!!! Unknown Error adding a deadline. Try Again.");
// System.out.println("E.g. deadline homework /by 20 Aug");
// }
// return taskCount;
// }
//
// private static int createEvent(String input, ArrayList<Task> tasks, int taskCount) {
// int fromIndex = input.indexOf("/from");
// int toIndex = input.indexOf("/to");
// //System.out.println(fromIndex);
// //System.out.println(toIndex);
// //System.out.println(input.length());
// if (fromIndex != -1 && toIndex != -1 && input.length() > 6 && fromIndex != 6 && toIndex != fromIndex + 6) {
// String eventDescription = input.substring(6, fromIndex).trim();
// String from = input.substring(fromIndex + 5, toIndex).trim();
// String to = input.substring(toIndex + 3).trim();
// tasks.add(new Event(eventDescription, from, to));
// taskCount++;
// System.out.println("Got it. I've added this task:");
// System.out.println("[E][ ] " + eventDescription + " (from: " + from + " to: " + to + ")");
// } else if (fromIndex == -1 || toIndex == -1 || toIndex == fromIndex + 6) {
// System.out.println(LINE + "\n☹ OOPS!!! Invalid Event format. Please use /from to specify the start of an event and /to to specify the end.");
// System.out.println("E.g. event project meeting /from 20 Aug 4pm /to 6pm");
// } else if (input.length() <= 6 || fromIndex == 6) {
// System.out.println(LINE + "\n☹ OOPS!!! Description of Event task needed!");
// System.out.println("E.g. event project meeting /from 20 Aug 4pm /to 6pm");
// } else {
// System.out.println(LINE + "\n☹ OOPS!!! Unknown Error adding an event. Try Again.");
// System.out.println("E.g. event project meeting /from 20 Aug 4pm /to 6pm");
// }
// return taskCount;
// }
//
// private static void printWelcomeMessage() {
// System.out.println(LINE);
// System.out.println("Hello! I'm Chatty!");
// System.out.println("What can I do for you?");
// System.out.println(LINE);
// }
}
11 changes: 11 additions & 0 deletions src/main/java/Chatty/Command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ public class Command {

String input;

/**
* initializes the Command class
* @param input input of the user
*/
public Command (String input){
this.input = input;
}

/**
* executes the command
* @param tasks passes the current task list
* @param ui passes the ui
* @param storage passes the storage
*/
public void execute (TaskList tasks, Ui ui, Storage storage){

}
Expand Down
34 changes: 28 additions & 6 deletions src/main/java/Chatty/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,57 @@ public class TaskList {

private final ArrayList<Task> tasks;

/**
* initializes the task list
* @param tasks list of tasks
*/
public TaskList(ArrayList<Task> tasks) {
this.tasks = tasks;
}

/**
* adds a task to the list
* @param task task to add
*/
public void addTask(Task task) {
tasks.add(task);
}

/**
* gets size of task list
* @return size of task list
*/
public int size(){
return tasks.size();
}

public Task get(int i){
return tasks.get(i);
/**
* get a specific task
* @param index index of task to get
* @return specific task
*/
public Task get(int index){
return tasks.get(index);
}

/**
* deletes a task
* @param index index of task to delete
*/
public void deleteTask(int index) {
tasks.remove(index);
}

/**
* mark task as done / not done
* @param index index of task to be mark done / not done
* @param isDone whether task is to be marked done / not done
*/
public void markTask(int index, boolean isDone){
if (isDone) {
tasks.get(index).mark();
} else {
tasks.get(index).unmark();
}
}

public ArrayList<Task> getAllTasks() {
return tasks;
}
}
18 changes: 18 additions & 0 deletions src/main/java/Chatty/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,46 @@

public class Ui {
public static final String LINE = "____________________________________________________________";

/**
* prints the welcome message
*/
public void printWelcomeMessage() {
System.out.println(LINE);
System.out.println("Hello! I'm Chatty!");
System.out.println("What can I do for you?");
System.out.println(LINE);
}

/**
* gets the user input
* @return user input
*/
public String getUserInput() {
Scanner scanner = new Scanner(System.in);
return scanner.nextLine();
}

/**
* prints the goodbye message
*/
public void printGoodbyeMessage() {
System.out.println(LINE);
System.out.println("Bye. Hope to see you again soon!");
System.out.println(LINE);
}

/**
* Shows error message when failed to load tasks from .txt file
*/
public void showLoadingError() {
System.out.println("Error loading or creating data file.");
}

/**
* prints any message
* @param message message to print
*/
public void printMessage(String message){
System.out.println(message);
}
Expand Down
Loading

0 comments on commit 304dedc

Please sign in to comment.