Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

ePortfolio

Problem Statement

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.

Assumptions

  • 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.

User Guide

Building and Running the Program

  1. Compile:
    • Run the following command to compile: cd asibak_a1 javac ePortfolio/Portfolio.java
  2. Run:
    • To run the program, execute: java ePortfolio.Portfolio
  3. 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.

Example Interaction

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.

Potential Improvements

  • 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.

About

ePortfolio is a Java console app for managing stock and mutual fund investments. It supports buy/sell, price updates, total gain calculation, and searches by symbol, name, or price. It applies a $9.99 commission for stocks and a $45 redemption fee for mutual funds.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages