Skip to content

Commit

Permalink
A-CodeQuality
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Feb 28, 2020
1 parent 0c4bd9c commit ca8245b
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 87 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
}

final def application = application {
mainClassName = "Main"
mainClassName = "Launcher"
}
application

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@
import java.time.LocalDate;

/**
* Class for Deadlines obj
* Class for Deadlines.
*/
public class Deadlines extends Task{
public class Deadlines extends Task {
protected String by;
private LocalDate date;

/**
* Deadline constructor.
* @param description description of deadlines
* @param isDone if task is done
* @param by deadline date in format yyyy-mm-dd
*/
public Deadlines(String description, Boolean isDone, String by) {
super(description, isDone);
this.by = by;
date = LocalDate.parse(by);
}

/**
* returns date of deadline.
* @return date task is due
*/
public String getDeadline() {
return this.by;
}

/**
* changes format of date.
* @return String value after modifying the date from yyyy-mm-dd to MMM DD YYYY
*/
@Override
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Circle;

/**
Expand Down Expand Up @@ -61,6 +60,12 @@ public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img);
}

/**
* returns flipped dialogbox.
* @param text text in dialogbox
* @param img image of duke
* @return returns a flipped dialogbox
*/
public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img);
db.flip();
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
public class Duke {

private DukeParser parser;
private DukeStorage storage;
private TaskList tasks;

/**
* Duke constructor.
*/
public Duke() {
String filePath = "tasks.txt";
DukeStorage storage = new DukeStorage(filePath);
TaskList tasks = storage.readText();
storage = new DukeStorage(filePath);
tasks = storage.readText();
parser = new DukeParser(tasks);
}

public void saveData() {
storage.saveTasks(tasks);
}

public String getResponse(String input) {
return parser.parseCommand(input);
}
Expand Down
110 changes: 55 additions & 55 deletions src/main/java/DukeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,88 +11,88 @@ public DukeParser(TaskList tasks) {
}

/**
*
* @param command
* parses user input as commands and generates a response.
* @param command user input
* @return Bot response after processing user's command
*/
public String parseCommand(String command) {

String[] command_broken = command.split(" ",2);
String[] commandBroken = command.split(" ",2);

String action = command_broken[0];
String action = commandBroken[0];

try {
try {

if (action.equalsIgnoreCase("bye")) {
return DukeUI.showByeMsg();
if (action.equalsIgnoreCase("bye")) {
return DukeUI.showByeMsg();

} else if (action.equalsIgnoreCase("list")) {
return tasks.printTasks();
} else if (action.equalsIgnoreCase("list")) {
return tasks.printTasks();

} else if (action.equalsIgnoreCase("done")) {
} else if (action.equalsIgnoreCase("done")) {

String context = command_broken[1];
int taskNo = Integer.parseInt(context);
String context = commandBroken[1];
int taskNo = Integer.parseInt(context);

return DukeUI.showDoneMsg(tasks.markDone(taskNo));
return DukeUI.showDoneMsg(tasks.markDone(taskNo));

} else if (action.equalsIgnoreCase("delete")) {
} else if (action.equalsIgnoreCase("delete")) {

String context = command_broken[1];
int taskNo = Integer.parseInt(context);
return tasks.removeTask(taskNo);
String context = commandBroken[1];
int taskNo = Integer.parseInt(context);
return tasks.removeTask(taskNo);

} else if (action.equalsIgnoreCase(("deadline"))) {
} else if (action.equalsIgnoreCase(("deadline"))) {

String context = command_broken[1];
String[] context_broken = context.split(" /by ", 2);
Task tempTask = tasks.addTask(new Deadlines(context_broken[0], false ,context_broken[1]));
return DukeUI.showCreationMsg(tempTask);
String context = commandBroken[1];
String[] contextBroken = context.split(" /by ", 2);
Task tempTask = tasks.addTask(new Deadlines(contextBroken[0], false, contextBroken[1]));
return DukeUI.showCreationMsg(tempTask);

} else if (action.equalsIgnoreCase(("todo"))) {
} else if (action.equalsIgnoreCase(("todo"))) {

if (command_broken.length == 1) {
throw new DukeException("THE DESCRIPTION OF TODO CANNOT BE EMPTY");
}
Task tempTask = tasks.addTask(new ToDos(command_broken[1], false));
return DukeUI.showCreationMsg(tempTask);
if (commandBroken.length == 1) {
throw new DukeException("THE DESCRIPTION OF TODO CANNOT BE EMPTY");
}
Task tempTask = tasks.addTask(new ToDos(commandBroken[1], false));
return DukeUI.showCreationMsg(tempTask);

} else if (action.equalsIgnoreCase(("event"))) {
} else if (action.equalsIgnoreCase(("event"))) {

String context = command_broken[1];
String[] context_broken = context.split(" /at ", 2);
Task tempTask = tasks.addTask(new Events(context_broken[0], false, context_broken[1]));
return DukeUI.showCreationMsg(tempTask);
String context = commandBroken[1];
String[] contextBroken = context.split(" /at ", 2);
Task tempTask = tasks.addTask(new Events(contextBroken[0], false, contextBroken[1]));
return DukeUI.showCreationMsg(tempTask);

} else if (action.equalsIgnoreCase("find")) {
} else if (action.equalsIgnoreCase("find")) {

int count = 1;
for (Task t : tasks.getAllTasks()) {
if (t.containsSubstring(command_broken[1])) {
System.out.println(count + "." + t);
count++;
}
int count = 1;
for (Task t : tasks.getAllTasks()) {
if (t.containsSubstring(commandBroken[1])) {
System.out.println(count + "." + t);
count++;
}
return DukeUI.showFindMsg();
} else if (action.equalsIgnoreCase("archive")) {

String context = command_broken[1];
int taskNo = Integer.parseInt(context);
return tasks.archiveTask(taskNo);
}
return DukeUI.showFindMsg();
} else if (action.equalsIgnoreCase("archive")) {

} else if (action.equalsIgnoreCase("archiveall")) {
String context = commandBroken[1];
int taskNo = Integer.parseInt(context);
return tasks.archiveTask(taskNo);

return tasks.archiveAll();
} else if (action.equalsIgnoreCase("archiveall")) {

} else if (action.equalsIgnoreCase("showarchive")){
return tasks.showArchived();
} else {
return "UNABLE TO COMPREHEND";
}
return tasks.archiveAll();

} catch (DukeException exception) {
System.out.println(exception.getMessage());
} else if (action.equalsIgnoreCase("showarchive")) {
return tasks.showArchived();
} else {
return "UNABLE TO COMPREHEND";
}

} catch (DukeException exception) {
System.out.println(exception.getMessage());
}
return "";
}
}
4 changes: 2 additions & 2 deletions src/main/java/DukeStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;

/**
* Handles all storage in duke
* Handles all storage in duke.
*/
public class DukeStorage {
private String filePath;
Expand All @@ -16,7 +16,7 @@ public DukeStorage(String filePath) {

/**
* Saves tasks to a .txt file in the same directory
* @param tasks
* @param tasks saves tasks
*/
public void saveTasks(TaskList tasks) {
List<Task> allTasks = tasks.getAllTasks();
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/DukeUI.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/**
* User interface class for DUke
* User interface class for Duke.
*/
public class DukeUI {

public DukeUI() {
}

public static String showWelcomeMessage () {
/**
* welcome message for duke.
* ToDo: use ascii art
* @return welcome message
*/
public static String showWelcomeMessage() {
StringBuilder sb = new StringBuilder();
sb.append("DEMOCRACY IS NON NEGOTIABLE\n\n");
sb.append( "HI I'M:\n\n LIBERTY PRIME" );
sb.append("HI I'M:\n\n LIBERTY PRIME");

return sb.toString();
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* Represents an Event object
* Represents an Event object.
*/
public class Events extends Task{
public class Events extends Task {
protected String at;

/**
* Event constructor.
* @param description description of event
* @param isDone checks if event is done
* @param at more description of event
*/
public Events(String description, Boolean isDone, String at) {
super(description, isDone);
this.at = at;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
/**
* Controller for MainWindow. Provides the layout for the other controls.
*/

public class MainWindow extends AnchorPane {

@FXML
private ScrollPane scrollPane;
@FXML
Expand Down Expand Up @@ -41,6 +42,10 @@ public void setDuke(Duke d) {
@FXML
private void handleUserInput() {
String input = userInput.getText();
if (userInput.getText().equalsIgnoreCase("bye")) {
duke.saveData();
Platform.exit();
}
String response = duke.getResponse(input);
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(input, userImage),
Expand All @@ -49,6 +54,9 @@ private void handleUserInput() {
userInput.clear();
}

/**
* greets user.
*/
public void dukeGreet() {
dialogContainer.getChildren().addAll(
DialogBox.getDukeDialog(DukeUI.showWelcomeMessage(), dukeImage),
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Represents a Task object
* Represents a Task object.
*/
public class Task {
protected String description;
Expand All @@ -12,11 +12,11 @@ public Task(String description, Boolean isDone) {

/**
* Creates a task using the .txt file at the start of the programme
* @param taskParams
* @param taskParams list of tasks as string of params
* @return New task added to Task List
* @throws RuntimeException
* @throws RuntimeException esception
*/
public static Task createStartingTask(String[] taskParams) throws RuntimeException{
public static Task createStartingTask(String[] taskParams) throws RuntimeException {
String type = taskParams[0];
boolean isDone = taskParams[1].equals("true");
String description = taskParams[2];
Expand Down Expand Up @@ -53,7 +53,7 @@ public String getDescription() {
}

/**
* Marks a task as done
* Marks a task as done.
*/
public Task markAsDone() {
this.isDone = true;
Expand Down
Loading

0 comments on commit ca8245b

Please sign in to comment.