Skip to content

Commit

Permalink
Update code with regards to Gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
Cazh1 committed Oct 16, 2023
1 parent b561971 commit 108544c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 50 deletions.
39 changes: 9 additions & 30 deletions src/main/java/seedu/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
package seedu.duke;

import seedu.duke.command.Command;
import seedu.duke.data.Menu;
import seedu.duke.parser.Parser;
import seedu.duke.ui.Ui;
import seedu.duke.command.ExitCommand;

import java.util.Scanner;

public class Duke {
/**
* Main entry-point for the java.duke.Duke application.
*/
private Ui ui;
private Menu menu;
public static void main(String[] args) {
new Duke().run();
}

/** Runs the program until termination. */
public void run() {
runCommandLoopUntilExitCommand();
exit(ui);
}
/** Reads the user command and executes it, until the user issues the exit command. */
public void runCommandLoopUntilExitCommand() {
do {
String item = ui.receiveUserInput();
Command c = Parser.parseCommand(menu, item);
c.execute(menu, ui);
} while (!ExitCommand.isExit());
}
private static void exit(Ui ui) {
ui.showGoodbye();
System.exit(0);
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("What is your name?");
Scanner in = new Scanner(System.in);
System.out.println("Hello " + in.nextLine());
}
}
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/command/AddDishCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* Adds a menu item to the user
*/
public class AddDishCommand extends Command {
Dish dish;
public static final String COMMAND_WORD = "add";
Dish dish;
public AddDishCommand(Dish dish) {
this.dish = dish;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/duke/command/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import seedu.duke.ui.Ui;

public class ExitCommand extends Command{
protected static boolean isExit = false;
public static final String COMMAND_WORD = "bye";
protected static boolean isExit = false;

@Override
public void execute(Menu menu, Ui ui) {
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/seedu/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,27 @@ public class Parser {
* @return the command based on the user input
*/
public static Command parseCommand(Menu menu, String userInput) {
String command[] = userInput.split(" ");
String[] command = userInput.split(" ");
switch (command[0].toLowerCase()) {
case ListMenuCommand.COMMAND_WORD:
return new ListMenuCommand();
/*case ListIngredientCommand.COMMAND_WORD:
return prepareListIngredient(menu,userInput);
case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(menu,userInput);*/
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
case AddDishCommand.COMMAND_WORD:
return new AddDishCommand();
default:
return new IncorrectCommand("Whoa there, tiger! Your command has left me scratching my virtual head. Let's try that again, shall we?");
case ListMenuCommand.COMMAND_WORD:
return new ListMenuCommand();
/*case ListIngredientCommand.COMMAND_WORD:
return prepareListIngredient(menu,userInput);
case DeleteDishCommand.COMMAND_WORD:
return prepareDelete(menu,userInput);*/
case ExitCommand.COMMAND_WORD:
return new ExitCommand();
case AddDishCommand.COMMAND_WORD:
//return new AddDishCommand();
return new IncorrectCommand("DEXTER DO WORK");
default:
return new IncorrectCommand("Your command has left me scratching my virtual head. " +
"Let's try that again, shall we?");
}
}

/**
*
* Parses arguments in the context of the ListIngredient command.
* @param menu
* @param userInput
* @return the prepared command
Expand Down Expand Up @@ -81,7 +83,8 @@ private static Command prepareDelete(Menu menu, String userInput) {
* @throws ParseException if no region of the args string could be found for the index
* @throws NumberFormatException the args string region is not a valid number
*/
private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command) throws ParseException, NumberFormatException {
private static int parseArgsAsDisplayedIndex(Menu menu, String userInput, String command)
throws ParseException, NumberFormatException {
String formattedString = userInput.replace(command, "").trim();
int listIndex = Integer.parseInt(formattedString);
return listIndex;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/duke/command/ListMenuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

class ListMenuCommandTest {
@Test
public static void execute_outputTwoDishes_() {
public static void execute_expectTwoDishes() {
ArrayList<Dish> menuItems = new ArrayList<>();
menuItems.add(new Dish("Chicken Rice", 2.50F));
menuItems.add(new Dish("Chicken Curry", 4.30F));
Menu menu = new Menu(menuItems);

Command ListMenuCommand = new ListMenuCommand();
ListMenuCommand.execute(menu, new Ui());
Command listMenuCommand = new ListMenuCommand();
listMenuCommand.execute(menu, new Ui());
}
}

0 comments on commit 108544c

Please sign in to comment.