A fully console-based stock market simulator written in Java. It uses design principles like MVC and Observer Pattern and is designed to simulate buying/selling stocks, updating stock prices, and tracking gainers/losers. π Features
π€ Single user portfolio management
π¦ Buy and sell stocks
πΉ Real-time stock price updates with change tracking
π Observer pattern to notify users of price changes
π Displays top gainers and losers based on price change
π Tech Stack
Java 17+
Object-Oriented Programming (OOP)
Design Patterns: MVC, Observer
π Project Structure
StockMarketSimulator/ βββ Main.java # Application entry point βββ StockMarket.java # Subject + Market logic βββ Stock.java # Stock entity with price tracking βββ User.java # Observer + portfolio logic βββ Observer.java # Observer interface βββ Subject.java # Subject interface
β How to Run
Clone or Download the project
Open in any Java IDE or use terminal
Compile all files: javac *.java java Main π§ͺ Sample Flow
===== Stock Market Simulator =====
- Buy Stock
- Sell Stock
- View Portfolio
- Update Stock Price
- Exit
Example: Buy AAPL, update its price, and see it appear as a top gainer.
π¦ Design Patterns Used
Observer Pattern: User observes StockMarket and gets notified when prices change
MVC:
Model: Stock, User
View: Console output
Controller: Main.java handles flow
π§ Possible Enhancements
Add multiple users
Export portfolio to CSV
Add persistence (save/load portfolio)
Build GUI (JavaFX / React + Spring Boot)