Skip to content

Commit

Permalink
Merge pull request #3 from TyrusLye/A-MoreOOP
Browse files Browse the repository at this point in the history
A more oop
  • Loading branch information
TyrusLye committed Oct 23, 2023
2 parents 4f32000 + c028425 commit e73f390
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 174 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ test {
}

application {
mainClass.set("seedu.duke.Duke")
mainClassName= "Launcher"
mainClass.set("URBOI_PACKIN")
mainClassName= "URBOI_PACKIN.Launcher"
}

shadowJar {
Expand Down
22 changes: 11 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ URBOI is a simple command-line chatbot designed to help you manage your tasks
- [Getting Started](#getting-started)
- [Adding Tasks](#adding-tasks)
- [Adding a To-Do](#adding-a-to-do)
- [Adding a Deadline](#adding-a-deadline)
- [Adding an Event](#adding-an-event)
- [Adding a URBOI_PACKIN.TaskTypes.Deadline](#adding-a-deadline)
- [Adding an URBOI_PACKIN.TaskTypes.Event](#adding-an-event)
- [Listing Tasks](#listing-tasks)
- [Marking Tasks as Done](#marking-tasks-as-done)
- [Deleting Tasks](#deleting-tasks)
- [Searching for Tasks](#searching-for-tasks)
- [Exiting Duke](#exiting-duke)
- [Exiting URBOI_PACKIN.ResponseController](#exiting-duke)
- [Saving Your Tasks](#saving-your-tasks)

## Getting Started<a name="getting-started"></a>

1. Clone or download the URBOI project code from [GitHub](https://github.com/TyrusLye/ip/releases/tag/A-Release).
2. Run the `URBOI.java` file to start the Duke chatbot.
2. Run the `URBOI.java` file to start the URBOI_PACKIN.ResponseController chatbot.

## Adding Tasks<a name="adding-tasks"></a>

Duke allows you to add three types of tasks: To-Do, Deadline, and Event.
URBOI_PACKIN.ResponseController allows you to add three types of tasks: To-Do, URBOI_PACKIN.TaskTypes.Deadline, and URBOI_PACKIN.TaskTypes.Event.

### Adding a To-Do<a name="adding-a-to-do"></a>

Expand All @@ -36,7 +36,7 @@ todo [description]

Replace `[task description]` with a brief description of the to-do task you want to add.

### Adding a Deadline <a name="adding-a-deadline"></a>
### Adding a URBOI_PACKIN.TaskTypes.Deadline <a name="adding-a-deadline"></a>

To add a deadline task, use the following command:

Expand All @@ -46,7 +46,7 @@ deadline [task description] /by [date and time]

Replace `[task description]` with a description of the deadline task and `[date and time]` with the date and time the task is due in the format `d/M/yyyy HHmm`.

### Adding an Event <a name="adding-an-event"></a>
### Adding an URBOI_PACKIN.TaskTypes.Event <a name="adding-an-event"></a>

To add an event task, use the following command:

Expand Down Expand Up @@ -103,14 +103,14 @@ To search for tasks containing a specific keyword, use the following command:
find [keyword]
```

Replace `[keyword]` with the keyword you want to search for. Duke will display a list of tasks matching your keyword.
Replace `[keyword]` with the keyword you want to search for. URBOI_PACKIN.ResponseController will display a list of tasks matching your keyword.

## 7. Exiting Duke <a name="exiting-duke"></a>
## 7. Exiting URBOI_PACKIN.ResponseController <a name="exiting-duke"></a>

To exit Duke, simply enter:
To exit URBOI_PACKIN.ResponseController, simply enter:

```plaintext
bye
```

Duke will bid you farewell and close.
URBOI_PACKIN.ResponseController will bid you farewell and close.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package URBOI_PACKIN;

import javafx.application.Application;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package URBOI_PACKIN;

import java.io.IOException;

import URBOI_PACKIN.UI.MainWindow;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
* A GUI for Duke using FXML.
* A GUI for URBOI_PACKIN.ResponseController using FXML.
*/
public class Main extends Application {

private Duke duke = new Duke();
private ResponseController responseController = new ResponseController();

@Override
public void start(Stage stage) {
Expand All @@ -20,7 +23,7 @@ public void start(Stage stage) {
AnchorPane ap = fxmlLoader.load();
Scene scene = new Scene(ap);
stage.setScene(scene);
fxmlLoader.<MainWindow>getController().setDuke(duke);
fxmlLoader.<MainWindow>getController().setDuke(responseController);
stage.show();
} catch (IOException e) {
e.printStackTrace();
Expand Down
158 changes: 11 additions & 147 deletions src/main/java/Duke.java → ...java/URBOI_PACKIN/ResponseController.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
import java.time.LocalDate;
package URBOI_PACKIN;

import URBOI_PACKIN.TaskTypes.Deadline;
import URBOI_PACKIN.TaskTypes.Event;
import URBOI_PACKIN.TaskTypes.Todo;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;

public class Duke {
public class ResponseController {
//private static final String FILE_PATH = "src/main/java/tasks.txt";
private static final String FILE_PATH = "tasks.txt/";
private static String response= "";
/**
* Main method to start the Duke application.
*
* @param args Command-line arguments.
*/
public static void main(String[] args) {
//Scanner scanner = new Scanner(System.in);
String logo = "UUUUUUUU UUUUUUUURRRRRRRRRRRRRRRRR BBBBBBBBBBBBBBBBB OOOOOOOOO IIIIIIIIII\n"
+"U::::::U U::::::UR::::::::::::::::R B::::::::::::::::B OO:::::::::OO I::::::::I\n"
+"U::::::U U::::::UR::::::RRRRRR:::::R B::::::BBBBBB:::::B OO:::::::::::::OO I::::::::I\n"
+"UU:::::U U:::::UURR:::::R R:::::RBB:::::B B:::::BO:::::::OOO:::::::OII::::::II\n"
+" U:::::U U:::::U R::::R R:::::R B::::B B:::::BO::::::O O::::::O I::::I \n"
+" U:::::D D:::::U R::::R R:::::R B::::B B:::::BO:::::O O:::::O I::::I \n"
+" U:::::D D:::::U R::::RRRRRR:::::R B::::BBBBBB:::::B O:::::O O:::::O I::::I \n"
+" U:::::D D:::::U R:::::::::::::RR B:::::::::::::BB O:::::O O:::::O I::::I \n"
+" U:::::D D:::::U R::::RRRRRR:::::R B::::BBBBBB:::::B O:::::O O:::::O I::::I \n"
+" U:::::D D:::::U R::::R R:::::R B::::B B:::::BO:::::O O:::::O I::::I \n"
+" U:::::D D:::::U R::::R R:::::R B::::B B:::::BO:::::O O:::::O I::::I \n"
+" U::::::U U::::::U R::::R R:::::R B::::B B:::::BO::::::O O::::::O I::::I \n"
+" U:::::::UUU:::::::U RR:::::R R:::::RBB:::::BBBBBB::::::BO:::::::OOO:::::::OII::::::II\n"
+" UU:::::::::::::UU R::::::R R:::::RB:::::::::::::::::B OO:::::::::::::OO I::::::::I\n"
+" UU:::::::::UU R::::::R R:::::RB::::::::::::::::B OO:::::::::OO I::::::::I\n"
+" UUUUUUUUU RRRRRRRR RRRRRRRBBBBBBBBBBBBBBBBB OOOOOOOOO IIIIIIIIII\n";

System.out.println("Wazzup! It's\n" + logo);
System.out.println("What can I do for you mah man?");
System.out.println("____________________________________________________________");

}


/**
* Process user input and generate a response.
Expand All @@ -53,7 +27,6 @@ public String getResponse(String command) {
try{
if (command.equalsIgnoreCase("bye")) {
response.append("Bye. Hope to see you again soon!");

} else if (command.equalsIgnoreCase("list")) {
response.append("Here are the tasks in your list:\n");
for (int i = 0; i < tasks.size(); i++) {
Expand All @@ -71,7 +44,7 @@ public String getResponse(String command) {
// Parse the date and time in the format d/M/yyyy HHmm
String[] parts = command.split(" /by ");
if (parts.length < 2) {
throw new DukeException("Deadline command must include a date.");
throw new DukeException("URBOI_PACKIN.TaskTypes.Deadline command must include a date.");
}
String description = parts[0].substring(9).trim();
LocalDateTime dateTime = LocalDateTime.parse(parts[1], DateTimeFormatter.ofPattern("d/M/yyyy HHmm"));
Expand Down Expand Up @@ -124,9 +97,6 @@ public String getResponse(String command) {
return response.toString();
}

private static String formatDate(LocalDate date) {
return date.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
}
/**
* Loads tasks from a file into the task list.
*
Expand All @@ -153,10 +123,10 @@ private static void loadTasksFromFile(ArrayList<Task> tasks) {
}

/**
* Creates a Task object from a line of text in the specified format.
* Creates a URBOI_PACKIN.Task object from a line of text in the specified format.
*
* @param line The line of text containing task details.
* @return A Task object representing the task described in the line, or null if parsing fails.
* @return A URBOI_PACKIN.Task object representing the task described in the line, or null if parsing fails.
*/
private static Task createTaskFromLine(String line) {
String[] parts = line.split(" \\| ");
Expand Down Expand Up @@ -234,114 +204,8 @@ private static void saveTasksToFile(ArrayList<Task> tasks) {
}



/**
* Represents a task that can be added to the task list.
*/
class Task {
protected String description;
protected boolean isDone;

protected LocalDateTime date;

public String toFileString() {
return "";
}
public String formatDate() {
return date.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
}
public Task(String description, LocalDateTime date) {
this.description = description;
this.isDone = false;
this.date = date;
}
public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]"); // Return a tick or cross symbol cuz im lazy like that, or its easier. idk
}
/**
* Get the description of the task.
*
* @return The description of the task.
*/
public String getDescription() {
return description;
}
public boolean isDone() {
return isDone;
}
public void markDone() {
isDone = true;
}
public void markNotDone() {
isDone = false;
}
@Override
public String toString() {
return "[" + (isDone ? "X" : " ") + "] " + description;
}
}

/**
* Represents a Todo task.
*/
class Todo extends Task {
public Todo(String description) {
super(description,null);
}
@Override
public String toFileString() {
return "T | " + (isDone ? "1" : "0") + " | " + description;
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}

/**
* Represents a Deadline task.
*/
class Deadline extends Task {
protected String by;

public Deadline(String description, LocalDateTime date) {
super(description, date);
}
@Override
public String toFileString() {
return "D | " + (isDone ? "1" : "0") + " | " + description + " | " + date;
}
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + date + ")";
}
}

/**
* Represents an Event task.
*/
class Event extends Task {
protected String from;
protected String to;

public Event(String description, String from, String to) {
super(description,null);
this.from = from;
this.to = to;
}
@Override
public String toFileString() {
return "E | " + (isDone ? "1" : "0") + " | " + description + " | " + from + " | " + to;
}
@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}
}

/**
* Custom exception class for Duke-specific exceptions.
* Custom exception class for URBOI_PACKIN.ResponseController-specific exceptions.
*/
class DukeException extends Exception {
public DukeException(String message) {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/URBOI_PACKIN/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package URBOI_PACKIN;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Task {

protected String description;
protected boolean isDone;

protected LocalDateTime date;

public String toFileString() {
return "";
}
public Task(String description, LocalDateTime date) {
this.description = description;
this.isDone = false;
this.date = date;
}
public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]"); // Return a tick or cross symbol cuz im lazy like that, or its easier. idk
}
/**
* Get the description of the task.
*
* @return The description of the task.
*/
public String getDescription() {
return description;
}
public boolean isDone() {
return isDone;
}
public void markDone() {
isDone = true;
}
public void markNotDone() {
isDone = false;
}
@Override
public String toString() {
return "[" + (isDone ? "X" : " ") + "] " + description;
}
}
25 changes: 25 additions & 0 deletions src/main/java/URBOI_PACKIN/TaskTypes/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package URBOI_PACKIN.TaskTypes;

import URBOI_PACKIN.Task;

import java.time.LocalDateTime;

/**
* Represents a Deadline task.
*/
public class Deadline extends Task {

public Deadline(String description, LocalDateTime date) {
super(description, date);
}

@Override
public String toFileString() {
return "D | " + (isDone ? "1" : "0") + " | " + description + " | " + date;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + date + ")";
}
}
Loading

0 comments on commit e73f390

Please sign in to comment.