Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Quote Command #257

Merged
merged 67 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
c984b98
Changed User Guide to include Quote Command
XavierLiau Apr 6, 2024
225e1fe
Updated User Guide with Quote Command
XavierLiau Apr 6, 2024
7d8f582
Added in Quote Command
XavierLiau Apr 6, 2024
93f2da3
Removed unecessary code
XavierLiau Apr 6, 2024
5a749db
Added Quotes Command
XavierLiau Apr 6, 2024
fcb92a0
Added Quote Command
XavierLiau Apr 7, 2024
acfe53b
Merge branch 'master' into master
XavierLiau34 Apr 7, 2024
253780c
Fixed Checkstyle Error
XavierLiau Apr 7, 2024
21a85d4
Merge branch 'master' of https://github.com/XavierLiau34/tp
XavierLiau Apr 7, 2024
4178228
merge remote changes
XavierLiau Apr 7, 2024
958a56b
Fixed Null Error
XavierLiau Apr 7, 2024
c797aaa
Added Tests For Quote Command
XavierLiau Apr 7, 2024
7f47edc
Fixed dos2unix error
XavierLiau Apr 7, 2024
fc20bb6
Corrected Expected Output
XavierLiau Apr 7, 2024
117b050
Fixed diff error
XavierLiau Apr 7, 2024
9c39c8c
Fixed Diff Error
XavierLiau Apr 7, 2024
fcc0d2c
Fixed Diff Error
XavierLiau Apr 7, 2024
a75c4bb
Solve Diff Error
XavierLiau Apr 7, 2024
26041af
Fixed Diff Error
XavierLiau Apr 8, 2024
397d9d5
Fixed Diff Error
XavierLiau Apr 8, 2024
93076f0
Fixed Diff Error
XavierLiau Apr 8, 2024
97baaa8
Fixed Diff Error
XavierLiau Apr 8, 2024
66e0ad3
Fixed Diff Error
XavierLiau Apr 8, 2024
264c5a8
Fixed Diff Error
XavierLiau Apr 8, 2024
dbc7bc7
Fixed Diff Error
XavierLiau Apr 8, 2024
b0890c6
Fixed Diff Error
XavierLiau Apr 8, 2024
3e456cd
Fixed DIff Error
XavierLiau Apr 8, 2024
94d479c
Fixed DIff Error
XavierLiau Apr 8, 2024
a151f96
Update EXPECTED.TXT
XavierLiau34 Apr 8, 2024
03194ac
Update runtest.bat
XavierLiau34 Apr 8, 2024
f63be8a
Update runtest.bat
XavierLiau34 Apr 8, 2024
10aa408
Update runtest.bat
XavierLiau34 Apr 8, 2024
c21b00f
Update runtest.bat
XavierLiau34 Apr 8, 2024
9fd8eab
Update runtest.bat
XavierLiau34 Apr 8, 2024
9c6016a
Update runtest.bat
XavierLiau34 Apr 8, 2024
b7b9f30
Update runtest.bat
XavierLiau34 Apr 8, 2024
67888ba
Update runtest.bat
XavierLiau34 Apr 8, 2024
c1dbdb5
Update runtest.bat
XavierLiau34 Apr 8, 2024
b4b36c4
Update runtest.bat
XavierLiau34 Apr 8, 2024
c50db75
Update runtest.bat
XavierLiau34 Apr 8, 2024
e6dadcc
Update runtest.bat
XavierLiau34 Apr 8, 2024
09c091d
Update runtest.bat
XavierLiau34 Apr 8, 2024
48ca7ef
Update runtest.bat
XavierLiau34 Apr 8, 2024
d97d771
Update runtest.bat
XavierLiau34 Apr 8, 2024
a0a8a47
Update runtest.bat
XavierLiau34 Apr 8, 2024
21b2a5b
Merge branch 'master' into master
XavierLiau34 Apr 8, 2024
f363fe5
Update UserGuide.md
XavierLiau34 Apr 8, 2024
282265b
Update BinBash.java
XavierLiau34 Apr 8, 2024
5ee94b8
Update Parser.java
XavierLiau34 Apr 8, 2024
ef9ba0d
Update runtest.bat
XavierLiau34 Apr 8, 2024
ea28150
Update BinBash.java
XavierLiau34 Apr 8, 2024
9c531d4
Update QuoteCommand.java
XavierLiau34 Apr 8, 2024
f5ebf46
Merge branch 'master' into master
XavierLiau34 Apr 8, 2024
1d055cc
Updated QuoteCommand
XavierLiau Apr 13, 2024
b69c499
Merge branch 'master' of https://github.com/XavierLiau34/tp
XavierLiau Apr 13, 2024
98ea2e1
Fixed Expected.txt error
XavierLiau Apr 13, 2024
08c6788
Updated Quote Command
XavierLiau Apr 13, 2024
3f23095
Added Tests for Search Command
XavierLiau Apr 13, 2024
250af4c
Increased Test Coverage
XavierLiau Apr 13, 2024
8e977de
Merge branch 'master' into master
XavierLiau34 Apr 13, 2024
a4e1e77
Fixed Test Coverage
XavierLiau Apr 13, 2024
6a43995
Merge branch 'master' of https://github.com/XavierLiau34/tp
XavierLiau Apr 13, 2024
b533480
Merge branch 'master' into master
XavierLiau34 Apr 14, 2024
9a5dbd6
Update Parser.java
XavierLiau34 Apr 14, 2024
dcd6513
Updated Test Coverage
XavierLiau Apr 14, 2024
41b9fa7
Fixed editing errors
XavierLiau Apr 14, 2024
b05ded3
Increased Test Coverage
XavierLiau Apr 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ This is a project template for a greenfield Java project. It's named after the J
Prerequisites: JDK 11 (use the exact version), update Intellij to the most recent version.

1. **Ensure Intellij JDK 11 is defined as an SDK**, as described [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk) -- this step is not needed if you have used JDK 11 in a previous Intellij project.
1. **Import the project _as a Gradle project_**, as described [here](https://se-education.org/guides/tutorials/intellijImportGradleProject.html).
1. **Verify the set up**: After the importing is complete, locate the `src/main/java/seedu/duke/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below:
2. **Import the project _as a Gradle project_**, as described [here](https://se-education.org/guides/tutorials/intellijImportGradleProject.html).
3. **Verify the set-up**: After the importing is complete, locate the `src/main/java/seedu/duke/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below:
```
> Task :compileJava
> Task :processResources NO-SOURCE
Expand Down Expand Up @@ -58,7 +58,7 @@ The project uses [GitHub actions](https://github.com/features/actions) for CI. W
Steps for publishing documentation to the public:
1. If you are using this project template for an individual project, go your fork on GitHub.<br>
If you are using this project template for a team project, go to the team fork on GitHub.
1. Click on the `settings` tab.
1. Scroll down to the `GitHub Pages` section.
1. Set the `source` as `master branch /docs folder`.
1. Optionally, use the `choose a theme` button to choose a theme for your documentation.
2. Click on the `settings` tab.
3. Scroll down to the `GitHub Pages` section.
4. Set the `source` as `master branch /docs folder`.
5. Optionally, use the `choose a theme` button to choose a theme for your documentation.
39 changes: 26 additions & 13 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ Format: `add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DAT

Examples:

- `add -op -n milk -d to make cofee -q 2 -e 03-10-2024 -c 1.30`<br>
- `add -op -n milk -d to make coffee -q 2 -e 03-10-2024 -c 1.30`<br>
```text
-------------------------------------------------------------
Noted! I have added the following item into your inventory:

[P][O] milk
description: to make cofee
description: to make coffee
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved
quantity: 2
cost price: $1.30
expiry date: 03-10-2024
Expand Down Expand Up @@ -640,6 +640,18 @@ Format: `bye`
* [Back to table of contents](#table-of-contents)
---

### Getting Inspirational Quotes: `quote`

> This command fetches a random quote to uplift your spirits.

Need a little motivation? The quote command retrieves random inspirational messages to brighten your day. Whether you're feeling stuck or just need a boost, BinBash has got you covered!

Format: `quote`

> ℹ️ BinBash brings you a variety of inspiring messages to keep you motivated throughout your inventory management journey. So go ahead, type quote and let the positivity flow!
* [Back to table of contents](#table-of-contents)
---

Copy link

@nur-haziq nur-haziq Apr 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an example of the quote output.

Nonetheless, good description. There's a strong display of user-friendliness.

### Saving and Loading data

Unsure as to how you can save your BinBash data? Don't worry! Your data is automatically saved to your local storage. No manual saving of data is required.
Expand All @@ -657,17 +669,18 @@ Similarly, your saved data will be automatically loaded into BinBash when you st

## Command Summary

| **Command** | **Usage** | **Description** |
|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| **add** | `add -re -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` <br> `add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -c COST_PRICE -t THRESHOLD` | Adds a new item to the inventory. |
| **search** | `search -n NAME_QUERY -d DESCRIPTION_QUERY -q QUANTITY_RANGE -c COST_PRICE_RANGE -s SALE_PRICE_RANGE -e EXPIRY_DATE_RANGE -l NUMBER_OF_RESULTS` | Searches for items in the inventory based on various criteria. |
| **list** | `list` <br> `list -c` <br> `list -s` <br> `list -e` <br> `list -p` | Lists all items in the inventory, with optional sorting based on cost price, sale price, expiry date or profits. |
| **delete** | `delete -i ITEM_INDEX` <br> `delete -n ITEM_NAME` | Deletes an item from the inventory. |
| **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY` <br> `sell -i ITEM_INDEX -q ITEM_QUANTITY` | Decreases the quantity of an item after a sale. |
| **restock** | `restock -n ITEM_NAME -q ITEM_QUANTITY` <br> `restock -i ITEM_INDEX -q ITEM_QUANTITY` | Increases the quantity of an item after restocking. |
| **update** | `update -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` <br> `update -i ITEM_INDEX -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` | Updates the details of an existing item in the inventory. |
| **profit** | `profit` | Displays the total profit earned from the inventory. |
| **bye** | `bye` <br> `exit` <br> `quit` | Exits the application. |
| **Command** | **Usage** | **Description** |
|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| **add** | `add -re -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` <br> `add -op -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -c COST_PRICE -t THRESHOLD` | Adds a new item to the inventory. |
| **search** | `search -n NAME_QUERY -d DESCRIPTION_QUERY -q QUANTITY_RANGE -c COST_PRICE_RANGE -s SALE_PRICE_RANGE -e EXPIRY_DATE_RANGE -l NUMBER_OF_RESULTS` | Searches for items in the inventory based on various criteria. |
| **list** | `list` <br> `list -c` <br> `list -s` <br> `list -e` <br> `list -p` | Lists all items in the inventory, with optional sorting based on cost price, sale price, expiry date or profits. |
| **delete** | `delete -i ITEM_INDEX` <br> `delete -n ITEM_NAME` | Deletes an item from the inventory. |
| **sell** | `sell -n ITEM_NAME -q ITEM_QUANTITY` <br> `sell -i ITEM_INDEX -q ITEM_QUANTITY` | Decreases the quantity of an item after a sale. |
| **restock** | `restock -n ITEM_NAME -q ITEM_QUANTITY` <br> `restock -i ITEM_INDEX -q ITEM_QUANTITY` | Increases the quantity of an item after restocking. |
| **update** | `update -n ITEM_NAME -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` <br> `update -i ITEM_INDEX -d ITEM_DESCRIPTION -q ITEM_QUANTITY -e EXPIRY_DATE -s SALE_PRICE -c COST_PRICE -t THRESHOLD` | Updates the details of an existing item in the inventory. |
| **profit** | `profit` | Displays the total profit earned from the inventory. |
| **quote** | `quote` | Displays a random quote on the screen. |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the 'Command Summary' table. 👍

This is extremely minor, but we would need to update the Key Definitions > Placeholders > COMMAND_WORD section as well.

| **bye** | `bye` <br> `exit` <br> `quit` | Exits the application. |

* [Back to table of contents](#table-of-contents)
---
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/binbash/BinBash.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private void run() {

userInterface.greet();
userInterface.talk(itemList.getProfitMargin());
userInterface.talk(userInterface.getRandomMessage());
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved

while (userInterface.isUserActive()) {
String userInput = userInterface.readUserCommand();
Expand All @@ -53,7 +54,7 @@ private void run() {
}
logger.info("BinBash exiting...");
}

/**
* Main entry-point for the BinBash application.
*/
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/seedu/binbash/command/QuoteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package seedu.binbash.command;

import seedu.binbash.inventory.ItemList;
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved
import seedu.binbash.quotes.Quotes;
import seedu.binbash.logger.BinBashLogger;

public class QuoteCommand extends Command {

public QuoteCommand() {
commandLogger = new BinBashLogger(QuoteCommand.class.getName());
commandLogger.info("Creating Quote Command...");
}

@Override
public boolean execute(ItemList itemList) {
executionUiOutput = Quotes.getRandomQuote();
return true;
}
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/binbash/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import seedu.binbash.command.SearchCommand;
import seedu.binbash.command.ListCommand;
import seedu.binbash.command.ProfitCommand;
import seedu.binbash.command.QuoteCommand;

import seedu.binbash.exceptions.BinBashException;

import seedu.binbash.exceptions.InvalidCommandException;

import org.apache.commons.cli.ParseException;
Expand Down Expand Up @@ -96,6 +99,8 @@ public Command parseCommand(String userInput) throws BinBashException {
return parseUpdateCommand(commandArgs);
case "profit":
return new ProfitCommand();
case "quote":
return new QuoteCommand();
default:
throw new InvalidCommandException("Invalid command: " + commandString);
}
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/seedu/binbash/quotes/Quotes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package seedu.binbash.quotes;

import java.util.Random;

public class Quotes {
public static final String[] CUSTOM_MESSAGES = {
"Hope you have a good day of inventory management.",
"Have a nice day!",
"Welcome back to BinBash!",
"Make today amazing!",
"Enjoy your time with BinBash!",
"Wishing you a productive day!",
"Get ready for some BinBash fun!",
"Let's make today great!",
"Time to conquer your inventory!",
"Sending positive vibes your way!",
"Welcome to another BinBash adventure!",
"Stay positive and keep BinBashing!",
"Today's a good day to organize!",
"You've got this!",
"Hope your day is BinBash-tastic!",
"Get ready to rock your inventory!",
"BinBash is here to help!",
"Hope you find everything you need!",
"Have a wonderful day ahead!",
"Start your day with a smile!",
"Sending you BinBash blessings!",
"Let's make magic happen!",
"Embrace the BinBash journey!",
"You're awesome, just like BinBash!",
"Seize the day with BinBash!",
"Welcome to BinBash excellence!",
"Time to unleash your inventory power!",
"Hope you have a blast with BinBash!",
"Today's a good day to BinBash!",
"Stay motivated and BinBash on!",
"Enjoy every moment with BinBash!",
"Make today memorable!",
"Let's create some BinBash miracles!",
"Believe in yourself and BinBash!",
"Welcome to the world of BinBash!",
"Today's forecast: BinBash brilliance!",
"BinBash wishes you a fantastic day!",
"May your day be filled with BinBash joy!",
"Let's make today legendary!",
"Stay positive and BinBash strong!"
};

private static final Random RANDOM = new Random();

// Private constructor to prevent instantiation
private Quotes() {}

public static String getRandomQuote() {
int randomIndex = RANDOM.nextInt(CUSTOM_MESSAGES.length);
return CUSTOM_MESSAGES[randomIndex];
}
}
24 changes: 15 additions & 9 deletions src/main/java/seedu/binbash/ui/Ui.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package seedu.binbash.ui;

import java.util.Random;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.EndOfFileException;
import org.jline.reader.UserInterruptException;
import org.jline.builtins.Completers.OptDesc;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;

import seedu.binbash.logger.BinBashLogger;

import java.io.IOException;
import java.util.ArrayList;
import seedu.binbash.quotes.Quotes;
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved

/**
* The user facing text interface of the program.
Expand All @@ -26,6 +26,7 @@ public class Ui {
private static final String WELCOME_MESSAGE = "Welcome to BinBash!";
private static final String LINE_DIVIDER = "-------------------------------------------------------------";
private static final BinBashLogger UILOGGER = new BinBashLogger(Ui.class.getName());
private static final Random RANDOM = new Random();

private static LineReader inputReader;
private static boolean isUserActive;
Expand All @@ -42,13 +43,13 @@ public Ui(ArrayList<ArrayList<OptDesc>> allCommandsOptionDescriptions) {
System.setProperty("org.jline.terminal.exec.redirectPipeCreationMode", "native");
try {
Terminal userTerminal = TerminalBuilder.builder()
.system(true)
.dumb(true) // TODO: omit and catch using logger
.build();
.system(true)
.dumb(true) // TODO: omit and catch using logger
.build();
inputReader = LineReaderBuilder.builder()
.terminal(userTerminal)
.completer(new CommandCompleter(allCommandsOptionDescriptions))
.build();
.terminal(userTerminal)
.completer(new CommandCompleter(allCommandsOptionDescriptions))
.build();
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved
} catch (IOException e) {
UILOGGER.info("failed to get system terminal!");
throw new RuntimeException(e);
Expand Down Expand Up @@ -82,7 +83,7 @@ public String readUserCommand() {
}

public void greet() {
talk(LOGO + WELCOME_MESSAGE);
talk(NEWLINE + LOGO + WELCOME_MESSAGE);
}

/**
Expand All @@ -93,4 +94,9 @@ public void greet() {
public void talk(String line) {
System.out.println(LINE_DIVIDER + NEWLINE + line + NEWLINE + LINE_DIVIDER);
}

public String getRandomMessage() {
int randomIndex = RANDOM.nextInt(Quotes.CUSTOM_MESSAGES.length);
return Quotes.CUSTOM_MESSAGES[randomIndex];
}
XavierLiau34 marked this conversation as resolved.
Show resolved Hide resolved
}
11 changes: 11 additions & 0 deletions src/test/java/seedu/binbash/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.binbash.command.Command;
import seedu.binbash.command.ListCommand;
import seedu.binbash.command.ByeCommand;
import seedu.binbash.command.QuoteCommand;
import seedu.binbash.exceptions.BinBashException;
import seedu.binbash.exceptions.InvalidCommandException;
import seedu.binbash.item.Item;
Expand Down Expand Up @@ -40,6 +41,16 @@ public void testParseCommand_validCommandBye_returnsByeCommand() {
}
}

@Test
public void testParseCommand_validCommandQuote_returnsQuoteCommand() {
try {
Command command = parser.parseCommand("quote");
assertTrue(command instanceof QuoteCommand);
} catch (BinBashException e) {
fail("Unexpected InvalidCommandException: " + e.getMessage());
}
}

@Test
public void testParseCommand_invalidCommand_throwsInvalidCommandException() {
assertThrows(InvalidCommandException.class, () -> parser.parseCommand("invalid"));
Expand Down
4 changes: 4 additions & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-------------------------------------------------------------

____ _ ____ _
| __ )(_)_ __ | __ ) __ _ ___| |__
| _ \| | '_ \| _ \ / _` / __| '_ \
Expand All @@ -13,6 +14,9 @@ Here are your metrics:
Total Revenue: 0.00
Net Profit: 0.00

-------------------------------------------------------------
-------------------------------------------------------------

-------------------------------------------------------------
binbash> -------------------------------------------------------------

Expand Down
Loading