How to Develop Vending Machine in JAVA

java program


Vending machine is a touch operated machine for selling various products. A new payment system was introduced which is using prepaid method. The objectives in this project are developing a vending machine and then insert a new payment method proposed into it. The specific problem having with vending machine is technical problem. Vending machine has many technical problems such as method of payment, level of security, very heavy structure, and product capacity.


This app is perform sale and purchase functions. It has six items that is to be purchased and also six options of money categories. The list of items are:

1: Pepsi $1.05

2: Mountain Dew $1.45

3: Coke $2.15

4: Diet Coke $ 2.95

5: Blood $ 9.95

6: Crab Juice $ 4.05

The list of amount Categories.

1: Dollar

2: Half Dollar

3: Quarter

4: Dime

5: Nickel

6: Coin Return

When we click on the amount option we will get the corresponding amount and display the amount. When we have enough amount to purchase items we click that item and purchase it. After purchased that item the system will display the receipt that will show how you have purchased item and show the remaining amount. The amount return option will return all amount that you have.




java program


java program


java program


java program


Three classes

Only start the application contain main function object of

All GUI work all controls button initialization in this class handling all GUI operation

Calls the function of class

Main implementation of algorithm for vending machine!

  • define items
  • define price for items
  • your current balance
  • manage all balance
  • manage report / invoice
  • BuyItem()
  • PrintMenu()
  • ReturnChange()
  • AddMoney()
  • PrettyMoney()

Algorithm of change return

Dollars = myTotal / 100;

myTotal -= (100 * Dollars);

HalfDollars = myTotal / 50;

myTotal -= (50 * HalfDollars);

Quarters = myTotal / 25;

myTotal -= (25 * Quarters);

Dimes = myTotal / 10;

myTotal -= (10 * Dimes);

Nickels = myTotal / 5;

myTotal -= (5 * Nickels);


Please enter your comment!
Please enter your name here