Abstract:
This project is a java related project.in this project we have designed how a vending machine can be programmed.And this vending machine program is programmed to be user friendly.with this program the user can choose what soft drink they want .The program is programmed to display the price list of the soft drink of there choice.This program is programmed like how a vending machine only dispenses four drinks at a time.Then we use looping to determine whether the user wants to continue or exit.if the user want to continue the program starts again from the beginning with what soft drink you want to buy?.Otherwise the program will come out and display the total cost of soft drinks purchased by the user.The program is programmed as is the user pays for it.If the user pays the appropriate amount ,it will say "Take your drinks","Have a nice day".May be if user pays more the program way that the total amount is subtracted by the user wallet amount .the program will return the balance amount to the user If the amount paid by user is below the appropriate amount. The program will display"not enough to pay "and the program will go to the payments enter section.If the user clicks anything wrong the specified values of soft drinks name ,price list and quantity.the program will display the another matching response.
package cooldrinks_vending_machine;
import java.util.Scanner; //In java we use a class called Scanner to receive input from the user.To use that class we need to import this package in java.
public class Machine {
static int choice,qty,option=1;
//When we refer to a Variables as Static.we can use its values and its names in all the sections in the program.
static float pur_cost,Total_cost=0,add_wallet=0,wallet_amount,bal_amt;
static void re_enter() {
//The program will enter this method.if the payment amount is not fine after the user finish.
System.out.println("please enter the enough amount to pay");
Machine ob= new Machine();
Scanner re=new Scanner(System.in);
add_wallet =re.nextFloat();
wallet_amount=add_wallet;
if(wallet_amount>=Total_cost)
{
bal_amt=wallet_amount-Total_cost;
System.out.println("Take your balance amount\n"+bal_amt+"₹");
System.out.print("Take your drinks\n");
System.out.println("-----HAVE A NICE DAY------- ");
}
else if (wallet_amount<Total_cost)
{
System.out.println("Wallet amount s not enough to pay \n");
ob.re_enter();
}
else {
System.out.print("Take your drinks\n");
System.out.println("-----HAVE A NICE DAY------- ");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("hello 😎 , sir/madam i am your helper.\n\n");
System.out.println("Look at the menu list before your purchase");
//First we will display what the cooldrinks are available.
while(option==1) {
System.out.print("1.Coca cola\n");
System.out.print("2.pepsi\n");
System.out.print("3.Fanta\n");
System.out.print("4.Maaza\n");
System.out.print("5.7up\n");
System.out.print("6.Frooti\n");
System.out.print("7.Maa\n");
System.out.print("8.Mountain due\n");
System.out.print("9.Bovanta\n");
System.out.print("10.Lechar soda\n");
System.out.print("11.Water\n\n");
System.out.println(" Select the suitable number. which one you want\t ");
//Then we use the Scanner class to let the user select which cool drink they want to select ?
Scanner sc=new Scanner(System.in);
choice=sc.nextInt();
{
System.out.println("Coca cola");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
//I have programmed only two values of cool drinks as default.
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==2)
{
System.out.println("Pepsi");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==3)
{
System.out.println("Fanta");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==4)
{
System.out.println("Maaza");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==5)
{
System.out.println("7up");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==6)
{
System.out.println("Frooti");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==7)
{
System.out.println("maa");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==8)
{
System.out.println("Mountain due");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==9)
{
System.out.println("Bovanta");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==10)
{
System.out.println("Lechar soda");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else if(choice==11)
{
System.out.println("Water");
System.out.println("Select the cost variant");
System.out.print("Choice 1. 40₹\t Choice 2. 60₹\t ");
choice=sc.nextInt();
if(choice==1)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=40*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price %.2f\t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else if(choice==2)
{
System.out.println("How many piece want to buy ");
qty=sc.nextInt();
if(qty<=4) {
pur_cost=60*qty;
Total_cost=Total_cost+pur_cost;
System.out.println("purchase price \t"+pur_cost+"₹");
}
else
{
System.out.println("No of quantity overload");
}
}
else {
System.out.println("OPTION NOT AVAILABLE ");
}
}
else {
System.out.println("OPTION NOT IN THE MENU");
}
System.out.println("if you want to continue your purchase :\nPress 1 to continue\nPress 2 to exit ");
//Every time the user completes their purchase we ask the user whether they want to restart or not.
option=sc.nextInt();
}
{
}
System.out.println("TOTAL AMOUNT WANT TO PAY :\t"+Total_cost);
//Here we display the total amount of the cool drinks purchased .if the user wants enough their purchase.
System.out.println("Enter your wallet amount :");
Machine ob=new Machine();
Scanner lk=new Scanner(System.in);
//we ask here to pay the money.
wallet_amount=lk.nextFloat();
if (wallet_amount<Total_cost)
//if the amount paid is less than to total.The program will have a method called re_enter() to display the payment form again
{
System.out.println("Wallet amount is not enough to pay \n");
ob.re_enter();
}
else if(wallet_amount>Total_cost)
//if the amount paid is higher than total.we deduct the amount paid from the total amount and give the balance to the user .
{
bal_amt=wallet_amount-Total_cost;
System.out.println("Take your balance amount\n"+bal_amt+"₹");
System.out.print("Take your drinks\n");
System.out.println("-----HAVE A NICE DAY------- ");
}
else {
//if the payment amount is correct to the total.Take your drinks and Have a nice day is displayed.
System.out.print("Take your drinks\n");
System.out.println("-----HAVE A NICE DAY------- ");
}
}
}
___________________________________________________________________________________