Skip to content

Repository files navigation

Python License

☕ Coffee Machine (OOP Version)

This is a Python coffee machine project where I rebuilt my earlier functional version using Object-Oriented Programming.

The idea was to make the code more structured and closer to how real systems are designed.

💡 What this project does

It simulates a simple coffee machine:

  • Lets you choose drinks (espresso, latte, cappuccino)
  • Checks if enough ingredients are available
  • Handles coin-based payments and returns change
  • Keeps track of profit
  • Stores transaction history
  • Saves everything so data is not lost after restart

🧠 Concepts Used

  • Object-Oriented Programming (Classes & Objects)
  • Encapsulation
  • Separation of Concerns
  • File Handling (JSON)
  • Modular Design

🧱 How I structured it (OOP approach)

I split the project into different classes so each part has its own responsibility:

  • CoffeeMachine → handles resources and making coffee
  • MoneyMachine → handles payments and profit
  • TransactionHistory → stores and shows past orders
  • StorageManager → loads and saves data using JSON

📦 Data storage

I used a data.json file to store:

  • Available resources (water, milk, coffee)
  • Total money earned
  • Transaction history

So even if you close the program, it remembers the previous state.

▶️ How to run

  1. Make sure Python is installed
  2. Run the following command (inside the project folder):
python main.py

🧠 What I learned from this

This project helped me understand:

  • How to break a big program into smaller parts
  • Why classes are useful
  • How objects manage their own data
  • How real-world systems are structured in code

📸 Sample Output

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: report
Water : 750
Milk : 450
Coffee : 316
Money : $8.5

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: history

🧾 Transaction History
------------------------------
cappuccino - $3.0
espresso - $1.5
latte - $2.5
espresso - $1.5

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: latte
How many quarters? 10
How many dimes? 25
How many nickels? 20
How many pennies? 19
 Here is $3.69 in change.
Here is your latte☕. Enjoy!

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: espresso
How many quarters? 56
How many dimes? 21
How many nickels? 10
How many pennies? 9
 Here is $15.19 in change.
Here is your espresso☕. Enjoy!

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: latttteee
Please choose a valid option.

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: latte
How many quarters? 20
How many dimes? 15
How many nickels? 14
How many pennies? ll
Invalid input. Please enter a number.
How many pennies? 51
 Here is $5.21 in change.
Here is your latte☕. Enjoy!

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: report
Water : 300
Milk : 150
Coffee : 250
Money : $15.0

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: history

🧾 Transaction History
------------------------------
cappuccino - $3.0
espresso - $1.5
latte - $2.5
espresso - $1.5
latte - $2.5
espresso - $1.5
latte - $2.5

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: refill
How much water to add (ml)200
How much milk to add (ml)100
How much coffee to add (g)50

☕ Coffee Menu
------------------------------
espresso ($1.5)
latte ($2.5)
cappuccino ($3.0)
Type 'refill' or 'report' or 'history' or 'off' 
Your choice: off
Machine has successfully switch off.

📌 Note

This is not a perfect project — I built it while learning OOP, so some parts may still be improved later.

About

Object-Oriented Coffee Machine simulator built in Python with JSON-based persistence (resources, profit, transaction history).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages