Skip to content

Commit

Permalink
Merge pull request #7 from gachia/branch-C-Help
Browse files Browse the repository at this point in the history
Completed C-Help
  • Loading branch information
gachia authored Sep 14, 2019
2 parents 173c9c2 + 53568f3 commit 2389358
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ checkstyle {

shadowJar {
archiveBaseName = "duke"
archiveVersion = "0.1.5"
archiveVersion = "0.1.6"
archiveClassifier = null
archiveAppendix = null
}

group 'duke'
version '0.1.5'
version '0.1.6'

repositories {
mavenCentral()
Expand Down
15 changes: 15 additions & 0 deletions src/main/data/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Here are the list of commands that you can use:
- todo <task name>
(saves a default To-Do task)
- deadline <task name> /by <date and time in D/MM/YYYY HHmm>
(saves a To-Do task with a deadline)
- event <event name> /at <venue>
(saves an Event task with a location)
- delete <task number>
(deletes a task from your list)
- done <task number>
(marks a task as done)
- list
(displays your task list)
- find <task name>
(find tasks with the search term)
2 changes: 0 additions & 2 deletions src/main/java/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import javafx.application.Platform;

/**
* Represents the Command for exiting the Duke Chatbot.
* A sub-class of Command.
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.image.Image;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
Expand All @@ -24,8 +25,9 @@ public void start(Stage stage) {
FXMLLoader fxmlLoader = new FXMLLoader(Gui.class.getResource("/view/MainWindow.fxml"));
AnchorPane ap = fxmlLoader.load();
Scene scene = new Scene(ap);
stage.setTitle("Duke: Your Virtual Assistant");
stage.setTitle("Duke: Your Task Assistant");
stage.setScene(scene);
stage.getIcons().add(new Image(Gui.class.getResourceAsStream("/images/dukeIcon.png")));
fxmlLoader.<MainWindow>getController().setDuke(duke);
stage.show();
} catch (IOException e) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Represents the Command for helping the user use the Chatbot.
* A sub-class of Command.
*/
public class HelpCommand extends Command {

/**
* Overridden execute method from Command to return the help message for the user.
* The help message details can be found in /data folder.
*
* @param storage Storage object for saving purposes
* @param tasks Contains the list of tasks
* @param ui Holds Ui printing methods and user input field
* @param input User input
* @return Help Message from UI
* @throws DukeException If help file is unable to be read in showHelp()
*/
@Override
public String execute(Storage storage, TaskList tasks, Ui ui, String input) throws DukeException {
return ui.showHelp();
}
}
1 change: 0 additions & 1 deletion src/main/java/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static Command parse(String userCmd) throws DukeException {
return new AddEventCommand();
case "deadline":
return new AddDeadlineCommand();
case "help":
return new HelpCommand();
default:
throw new DukeException("Invalid Command");
}
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

/**
* Handles the printing of Duke messages.
Expand All @@ -7,12 +9,14 @@ public class Ui {

final String lineSpace = "_______________________________\n";
private Scanner sc;
final String helpFilePath;

/**
* Default Constructor to initialise Scanner object for user input.
*/
public Ui() {
sc = new Scanner(System.in);
helpFilePath = "src/main/data/help.txt";
}

/**
Expand All @@ -21,14 +25,16 @@ public Ui() {
* @return welcome message
*/
public String showWelcome() {
/*
final String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
final String startMessage = "Hello! I'm Duke\nWhat can I do for you?\n";
String welcomeMessage = startMessage;
return welcomeMessage;
*/
final String startMessage = "Hello! I'm Duke, Your Task Assistant.\n"
+ "What can I do for you?\n" + "If you need help, type help in the field.";
return startMessage;
}

/**
Expand Down Expand Up @@ -89,6 +95,25 @@ public String showDelete(Task task, int listSize) {
return message;
}

/**
* Prints a help message that lists the available commands the user is able
* to type. Message is read from a text file in /data folder.
*
* @return Help Message
* @throws DukeException If file is unable to be read
*/
public String showHelp() throws DukeException {
try {
File f = new File(helpFilePath);
Scanner sc = new Scanner(f);
String helpMessage = sc.useDelimiter("\\A").next();
sc.close();
return helpMessage;
} catch (FileNotFoundException e) {
throw new DukeException("Failed to load help text file");
}
}


/**
* Prints a straight line for clarity purposes.
Expand Down
Binary file added src/main/resources/images/dukeIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2389358

Please sign in to comment.