From 07ecdbb67666843d91e6d9e6de9e48bd60871576 Mon Sep 17 00:00:00 2001 From: Daniel Adi Date: Tue, 15 Sep 2020 23:13:45 +0800 Subject: [PATCH] Remove redundant code --- src/main/java/duke/Duke.java | 57 +++-------------------------------- src/main/java/duke/ui/Ui.java | 34 +-------------------- 2 files changed, 5 insertions(+), 86 deletions(-) diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java index 31f09f8e8d..f6189ea0aa 100644 --- a/src/main/java/duke/Duke.java +++ b/src/main/java/duke/Duke.java @@ -1,20 +1,5 @@ package duke; -import java.io.IOException; - -import javafx.application.Application; -import javafx.scene.Scene; -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.Region; -import javafx.scene.layout.VBox; -import javafx.stage.Stage; - import duke.exceptions.DukeException; import duke.logic.CommandParser; import duke.logic.commands.Command; @@ -34,15 +19,6 @@ public class Duke { private TaskManager tm; private Ui ui; - private ScrollPane scrollPane; - private VBox dialogContainer; - private TextField userInput; - private Button sendButton; - private Scene scene; - - private Image user = new Image(this.getClass().getResourceAsStream("/images/User.jpg")); - private Image duke = new Image(this.getClass().getResourceAsStream("/images/Duke.jpg")); - /** * Constructor for Duke class. * Initiates the User Interface and tries to load save file from disk. @@ -59,26 +35,11 @@ public Duke() { } /** - * This is the method that processes user input and looks out for the exit signal. + * Generates response to command input. + * + * @param input String input by user. + * @return Response after command is executed. */ - public void run() { - ui.showWelcome();; - boolean isExit = false; - while (!isExit) { - try { - String fullCommand = ui.readCommand(); - ui.showLine(); - Command c = CommandParser.parse(fullCommand); - c.execute(tm, ui, storage); - isExit = c.isExit(); - } catch (DukeException e) { - ui.showError(e); - } finally { - ui.showLine(); - } - } - } - public String getResponse(String input) { try { Command c = CommandParser.parse(input); @@ -87,14 +48,4 @@ public String getResponse(String input) { return e.getMessage(); } } - - /** - * This is the main method that runs Duke. - * - * @param args Unused. - * @throws IOException On input error. - */ - public static void main(String[] args) throws IOException { - new Duke().run(); - } } diff --git a/src/main/java/duke/ui/Ui.java b/src/main/java/duke/ui/Ui.java index 29397a4be9..b4c181e727 100644 --- a/src/main/java/duke/ui/Ui.java +++ b/src/main/java/duke/ui/Ui.java @@ -11,32 +11,8 @@ public class Ui { static final String WELCOME = "Hello. I am Claude! What may I do for you today?"; static final String GOODBYE = "Goodbye! Hope to see you again soon!"; - static final String LINE = "______________________________"; - private Scanner sc; - public Ui() { - this.sc = new Scanner(System.in); - } - - /** - * Reads command input by user. - * - * @return String to be processed by parser. - */ - public String readCommand() { - if (sc.hasNext()) { - return sc.nextLine(); - } else { - return ""; - } - } - - /** - * Prints a line that serves as a divider. - */ - public void showLine() { - System.out.println(LINE); - } + public Ui() {} /** * Prints welcome message. @@ -52,14 +28,6 @@ public String showGoodbye() { return (GOODBYE); } - /** - * Prints output from a Command. - * @param s String to be printed. - */ - public void showDetails(String s) { - System.out.println(s); - } - /** * Prints a given ArrayList of Tasks. * @param taskList ArrayList of Tasks to be printed.