Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Business Game 🏦

A Monopoly-style business simulation game built in Java, featuring real-time stock price fluctuations, property trading across 26 world cities, and multi-player account management β€” all played through an interactive console.


Table of Contents


Features

Feature Description
Multi-player accounts Up to 100 player accounts with PIN authentication
Live stock market Background thread fluctuates the share price Β±$10 every 10 seconds
ASCII stock chart Price history visualised in the terminal
Property trading Buy/sell city properties across 26 world cities
Round inflation Type 11 to end a round and apply 5 % price inflation to all properties
Fund transfers Securely move money between accounts
Save to file Persist account balances to accounts.txt

Project Structure

BusinessGame/
β”œβ”€β”€ pom.xml                                 ← Maven build file
β”œβ”€β”€ README.md
└── src/
    └── main/
        └── java/
            └── com/businessgame/
                β”œβ”€β”€ Main.java               ← Entry point & dependency wiring
                β”‚
                β”œβ”€β”€ model/                  ← Pure domain objects (no I/O)
                β”‚   β”œβ”€β”€ Account.java        ← Player account: balance, shares, properties
                β”‚   └── Property.java       ← City/country: name, price, index
                β”‚
                β”œβ”€β”€ service/                ← Business logic layer
                β”‚   β”œβ”€β”€ AccountRegistry.java    ← In-memory account store
                β”‚   β”œβ”€β”€ PropertyMarket.java     ← Property catalogue & round inflation
                β”‚   β”œβ”€β”€ StockMarket.java        ← Thread-safe share price + fluctuator
                β”‚   β”œβ”€β”€ StockChart.java         ← ASCII chart renderer
                β”‚   └── SaveService.java        ← Persist accounts to file
                β”‚
                β”œβ”€β”€ ui/                     ← Console I/O handlers
                β”‚   β”œβ”€β”€ GameMenu.java           ← Main game loop & top-level menu
                β”‚   β”œβ”€β”€ AccountUI.java          ← Account commands (create, balance, …)
                β”‚   β”œβ”€β”€ PropertyUI.java         ← Property sub-menu
                β”‚   └── MarketUI.java           ← Stock market sub-menu
                β”‚
                └── util/
                    └── InputHelper.java        ← Safe Scanner wrapper with retry logic

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Main.java                 β”‚
β”‚  Wires services β†’ GameMenu β†’ runs game loop β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚       GameMenu        β”‚
        β”‚  (top-level commands) β”‚
        β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
           β”‚      β”‚      β”‚
     AccountUI PropertyUI MarketUI
           β”‚      β”‚      β”‚
           β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”¬β”€β”€β”€β”˜
                     β”‚  delegates to
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚      Services       β”‚
          β”‚  AccountRegistry    β”‚
          β”‚  PropertyMarket     β”‚
          β”‚  StockMarket        β”‚
          β”‚  SaveService        β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚  owns
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚       Models        β”‚
          β”‚  Account            β”‚
          β”‚  Property           β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

All I/O is confined to the ui package. Services and models have zero System.out dependencies β€” they throw typed exceptions that the UI layer catches and presents as friendly messages.


Getting Started

Prerequisites

  • Java 17 or later
  • Maven 3.8+ (or use the included wrapper if present)

Build

mvn clean package

This produces a runnable fat-jar at target/business-game-1.0.0.jar.

Run

java -jar target/business-game-1.0.0.jar

Or run directly from source:

mvn exec:java -Dexec.mainClass=com.businessgame.Main

How to Play

On launch you will see the main menu. Type the number for the action you want and press Enter.

╔══════════════════════════════════════╗
β•‘         BUSINESS GAME  v1.0          β•‘
╠══════════════════════════════════════╣
β•‘   0  Check balance                   β•‘
β•‘   1  Add balance                     β•‘
β•‘   2  Withdraw funds                  β•‘
β•‘   3  Property dealing                β•‘
β•‘   4  Transfer funds                  β•‘
β•‘   5  Stock market                    β•‘
β•‘   7  Save game to file               β•‘
β•‘   9  New account                     β•‘
β•‘  11  End of round                    β•‘
β•‘  99  Quit                            β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Typical game flow

  1. Create accounts β€” each player types 9 to register with a unique account number and PIN.
  2. Add starting money β€” the banker types 1 and deposits the agreed starting amount (a 10 % bonus is added automatically).
  3. Take turns β€” players buy/sell properties (3) and trade on the stock market (5).
  4. End each round β€” type 11 to advance the round; all property prices rise by 5 %.
  5. Save progress β€” type 7 to write balances to accounts.txt.
  6. Quit β€” type 99 when the game ends.

Available cities / countries

Code City Start Price
new New York $8,500
rom Rome $3,000
hon Hong Kong $2,500
syd Sydney $4,500
dub Dubai $5,000
kua Kuala Lumpur $3,500
deh Delhi $4,500
ber Berlin $5,000
rai Riyadh $9,500
zur Zurich $5,500
tok Tokyo $3,500
lon London $4,500
air (top city) $10,500
mos Moscow $5,000
… … …

Class Reference

model/Account

Encapsulates all per-player state: balance, share count, property holdings, and PIN. Throws IllegalArgumentException / IllegalStateException on invalid operations β€” callers never check raw array bounds.

model/Property

Immutable city descriptor with a mutable price. applyRoundInflation() applies the 5 % round increase.

service/AccountRegistry

HashMap-backed store replacing the original parallel arrays. Provides find(accountNumber) and authenticate(accountNumber, password) returning Optional<Account>.

service/PropertyMarket

Holds the catalogue of 26 Property objects. findByName() is case-insensitive. applyRoundInflation() delegates to each property.

service/StockMarket

Maintains an AtomicInteger share price, safe for concurrent access. Starts a daemon thread that fluctuates the price Β±$10 every 10 seconds and prints an updated chart.

service/StockChart

Static utility β€” renders an ASCII bar chart of a price-history array. Separated from StockMarket so it can be tested independently.

service/SaveService

Writes all account balances to accounts.txt using a BufferedWriter inside a proper try-with-resources block.

ui/GameMenu

Main loop. Maps integer commands to handler calls. All sub-menus loop internally and return control here when the user exits.

ui/AccountUI, ui/PropertyUI, ui/MarketUI

Thin console-interaction layers. Each reads input via InputHelper, calls service/model methods, and prints results or exception messages.

util/InputHelper

Wraps Scanner. readInt(), readLong(), and readWord() retry indefinitely on bad input instead of crashing with InputMismatchException.


Known Bugs Fixed

# Original issue Fix
1 Data race on static int stockprice mutated from two threads Replaced with AtomicInteger in StockMarket
2 InputMismatchException crash on non-integer input InputHelper retries with a clear error message
3 Fernflower decompiler garbage (var0, var10000, nested Throwable catch) in saveToFile Rewritten with proper try-with-resources
4 static int o counter in main() breaks if account creation fails (counter still incremented) AccountRegistry uses a HashMap; no index needed
5 checkPrice() had a pointless try/catch(Exception) around System.out.println Removed
6 propertyDealing() used while(as == 0) flag instead of a boolean Replaced with clean boolean active loop
7 No validation β€” negative amounts, zero-division, array out-of-bounds all possible Every model method validates input and throws typed exceptions
8 Stock price could go to 0 or negative with repeated bad ticks Math.max(MIN_PRICE, ...) guard in fluctuator
9 createAccount used a separate o index that was never bounds-checked Registry enforces MAX_ACCOUNTS with a clear error
10 No way to exit the game cleanly Added command 99 and a JVM shutdown hook

Future Improvements

  • Persistence β€” load accounts.txt on startup to resume a saved game
  • Password hashing β€” use BCrypt instead of storing plain-text PINs
  • GUI β€” Swing or JavaFX board view
  • Network play β€” expose services over sockets or REST for remote players
  • Unit tests β€” JUnit 5 tests for model layer (no I/O required)
  • Event system β€” Chance/Community Chest cards that trigger random events

About

As a 6th grader, I played Business board game a lot. One day, I lost most of the cash and cards, so I wrote a program for it. This repo isn't the raw code I wrote as a kid, I've heavily modified and improved it since then.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages