This ePortfolio program is a system that allows a user to manage investments in stocks and mutual funds. Users can buy, sell, update prices, and search for investments. Additionally, the program calculates the total gain of the portfolio and handles financial transactions such as stock commissions and mutual fund redemption fees.
- Stocks: There is a $9.99 commission fee when stocks are bought or sold.
- Mutual Funds: There is a $45 redemption fee when mutual funds are sold, but no fee when buying.
- Investment Types: The system handles two types of investments, stocks and mutual funds, which have slightly different transaction rules.
- Compile:
- Run the following command to compile: cd asibak_a1 javac ePortfolio/Portfolio.java
- Run:
- To run the program, execute: java ePortfolio.Portfolio
- Commands:
- buy: Buy a new stock or mutual fund or add to an existing one.
- sell: Sell part or all of an existing stock or mutual fund.
- update: Update the prices of stocks and mutual funds in the portfolio.
- getGain: Calculate and display the total gain of the portfolio.
- search: Search for investments by symbol, name keywords, and/or price range.
- quit: Exit the program.
Enter a command (buy, sell, update, getGain, search, quit):
Test 1: Buying a Stock Input: buy stock AAPL Apple Inc. 100 150.00 Expected Output: New investment added.
Test 2: Buying More Shares of an Existing Stock Input: buy stock AAPL 50 200.00 Expected Output: Investment exists. Enter additional quantity and new price. Stock updated.
Test 3: Buying a Mutual Fund Input: buy mutualfund VFIAX Vanguard 500 Index Fund 200 250.00 Expected Output: New investment added.
Test 4: Selling a Portion of Stock Input: sell AAPL 50 180.00 Expected Output: Sold 50 shares of AAPL for $8890.01.
Test 5: Selling All Shares of Stock Input: sell AAPL 100 190.00 Expected Output: Sold 100 shares of AAPL for $18990.01.
Test 6: Selling a Mutual Fund Input: sell VFIAX 100 260.00 Expected Output: Sold 100 units of VFIAX for $25955.00.
Test 7: Updating Prices Input: update Enter new price for stock AAPL: 210.00 Enter new price for mutual fund VFIAX: 270.00 Expected Output: Prices updated.
Test 8: Getting Total Gain Input: getgain Expected Output: Total gain: $XXXX.XX
Test 9: Searching by Symbol Input: search AAPL Expected Output: Stock{symbol='AAPL', name='Apple Inc.', quantity=100, price=210.0, bookValue=...}
Test 10: Searching by Name Keywords Input: search Vanguard Expected Output: MutualFund{symbol='VFIAX', name='Vanguard 500 Index Fund', quantity=100, price=270.0, bookValue=...}
Test 11: Searching by Price Range Input: search 100.00-300.00 Expected Output: Stock{symbol='AAPL', name='Apple Inc.', quantity=100, price=210.0, bookValue=...} MutualFund{symbol='VFIAX', name='Vanguard 500 Index Fund', quantity=100, price=270.0, bookValue=...}
Test 12: Invalid Symbol Search Input: search XYZ Expected Output: No investments found matching the search criteria.
Test 13: Invalid Sell Quantity Input: sell AAPL 1000 250.00 Expected Output: Error: Not enough shares to sell.
Test 14: Invalid Buy Quantity Input: buy stock AAPL -50 200.00 Expected Output: Error: Invalid quantity.
- Add persistence by saving the portfolio data to a file, so that users can resume managing their portfolio after restarting the program.
- Improve error handling for more graceful responses to unexpected input formats.