forked from nus-cs2103-AY1920S2/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from sheexiong/master
Add ListAmount and DeleteItem Command and Parser, adding new UI class to help format the output to CLI.
- Loading branch information
Showing
9 changed files
with
177 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 37 additions & 2 deletions
39
src/main/java/seedu/eylah/expensesplitter/logic/commands/DeleteItemCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,42 @@ | ||
package seedu.eylah.expensesplitter.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.eylah.commons.core.index.Index; | ||
import seedu.eylah.expensesplitter.logic.commands.exceptions.CommandException; | ||
import seedu.eylah.expensesplitter.model.Model; | ||
|
||
/** | ||
* Delete item from the receipt. | ||
* Deletes an item from the list of available items. | ||
*/ | ||
public class DeleteItemCommand { | ||
public class DeleteItemCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "deleteItem"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the item identified by the index number used in the displayed item list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteItemCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.deleteEntry(targetIndex.getZeroBased()); | ||
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, targetIndex.getOneBased())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteItemCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeleteItemCommand) other).targetIndex)); // state check | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/seedu/eylah/expensesplitter/logic/commands/ListAmountCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package seedu.eylah.expensesplitter.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.eylah.expensesplitter.model.Model; | ||
|
||
/** | ||
* Lists all users with their amount. | ||
*/ | ||
public class ListAmountCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "listamount"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all person with their amount."; | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.listAmount(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/seedu/eylah/expensesplitter/logic/parser/DeleteItemCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package seedu.eylah.expensesplitter.logic.parser; | ||
|
||
import static seedu.eylah.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.eylah.commons.core.index.Index; | ||
import seedu.eylah.expensesplitter.logic.commands.DeleteItemCommand; | ||
import seedu.eylah.expensesplitter.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteItemCommand object | ||
*/ | ||
public class DeleteItemCommandParser implements Parser<DeleteItemCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public DeleteItemCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new DeleteItemCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteItemCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/eylah/expensesplitter/logic/parser/ListAmountCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package seedu.eylah.expensesplitter.logic.parser; | ||
|
||
import static seedu.eylah.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.eylah.expensesplitter.logic.commands.ListAmountCommand; | ||
import seedu.eylah.expensesplitter.logic.commands.ListReceiptCommand; | ||
import seedu.eylah.expensesplitter.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new ListAmountCommand object. | ||
*/ | ||
public class ListAmountCommandParser implements Parser<ListAmountCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ListReceiptCommand | ||
* and returns an ListReceiptCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
@Override | ||
public ListAmountCommand parse(String args) throws ParseException { | ||
|
||
if (args.equals("listamount")) { | ||
return new ListAmountCommand(); | ||
} else { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListReceiptCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
package seedu.eylah.ui; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* Main CLI Ui component for the application. | ||
*/ | ||
public class Ui { | ||
|
||
private static final String WELCOME_MESSAGE = "Welcome to EYLAH, this is a debug version of interface :)"; | ||
private static final String USAGE = "To use the application, enter `diet` or " | ||
+ "`splitter` to enter the different mode."; | ||
private static final String LS = System.lineSeparator(); | ||
|
||
private Scanner scanner; | ||
|
||
public Ui() { | ||
scanner = new Scanner(System.in); | ||
} | ||
|
||
private void showToUser(String... message) { | ||
for (String m : message) { | ||
System.out.println(m.replace("\n", LS)); | ||
} | ||
} | ||
|
||
public String readCommand() { | ||
return scanner.nextLine(); | ||
} | ||
|
||
public void showWelcome() { | ||
showToUser(WELCOME_MESSAGE, USAGE); | ||
} | ||
|
||
public static String formatListAmount() { | ||
return ""; | ||
} | ||
|
||
} |