Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create an application for a vending machine ithat dispenses items such as snacks

ID: 3776669 • Letter: C

Question

create an application for a vending machine ithat dispenses items such as snacks ( 5 types) and beverages (at least 5types), to customers automatically, after the customer inserts currency the machine. The application should display the list of all items available to thecustomer and should return the balance money to the customer after dispensing the requested item. this is for java can the gui have pictures and buttons and stuff thanks. it has to look good thanks everyone a good java code please I appreciate it gui please thanks

Explanation / Answer

import.java.util.scanner;
public class Machine
{
public static void main (String args[])
{
int[4] coin = {5,5,5,5};//create an array to hold coin values
int[4] snack = {5,5,5,5}; //create an array to hold snack values
int choice;
char cont;
//String input1, input2, input3;
double price = 1.2, balance = 0, coinInsert = 0, sumCoininsert = 0;
showmenu(coin, snack);
sumCoininsert = inputcoin(coinInsert);
showSnacks(choice);
showbalace(sumCoininsert, price);
contmethod(cont);
}
/*****************menu method*****************/
public static int showmenu (int coin, int snack)
{
int coin;
int snack;
System.out.println("[Coins available : RM 1 [" + coin[0] + "] RM0.50 [ " + coin[1] + "] RM 0.20 [ " + coin[2] + "] RM0.10 [" +coin[3] "] ]");
System.out.println("[snacks available : Lays [" + snack[0] + "] kurkuri [" + snack[1] + "] 5 Star [" + snack[2] + "] Dairymilk [" + snack[3] + "] ]");
}
/********************menu method*****************/
/**************inputcoin method *******************/
public static double inputcoin (double coinInsert)
{
double coinInsert = 0, sumCoininsert = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Insert Coin==>");
double coinInsert = sc.nextDouble();
while (coinInsert == '1' || coinInsert == '0.5' || coinInsert == '0.2' || coinInsert == '0.1')
{
coinInc(coinInsert);
sumCoininsert = sumCoininsert + coinInsert;
while (sumCoinInsert < 1.20)
{
System.out.println("Insert Coin==>");
double coinInsert = sc.nextDouble();
}
}
System.out.println (" Total :" +sumCoinInsert);
}
/********************inputcoin method*******************/
/***************coinInc method************************/
public static double coinInc(int coinInsert)
{
double coinInsert;
Scanner sc = new Scanner(System.in);
switch (coinInsert) {
case coinInsert == '1':
coin[0]++;
break;
case coinInsert == '0.5':
coin[1]++;
break;
case coinInsert == '0.2':
coin[2]++;
break;
case coinInsert == '0.1':
coin[3]++;
break;
default:
System.out.println("Invalid coin");
sumCoininsert = 0;
System.out.println("Insert Coin==>");
double coinInsert = sc.nextDouble();
break;
}
}
/******************coinInc method*********************/
/*****************snacks method **************/
public static int showsnacks (int choice)
{
int choice;
System.out.println("Snackss [RM1.20]");
System.out.println("1.Lays" " 2.Kurkuri" " 3.5 Star" " 4.Dairymilk");
Scanner sc = new Scanner(System.in);
System.out.println("Choice==>");
int choice = sc.nextInt();
while (choice == '1' || choice == '2' || choice == '3' || choice == '4')
{
if (choice =='1')
{
snack[0]--;
}
else if (choice=='2')
{
snack[1]--;
}
else if (choice =='3')
{
drink[2]--;
}
else (choice == '4')
{
snack[3]--;
}
}
System.out.println("Invalid choice");
System.out.println("Choice==>");
int choice = sc.nextInt();
}
/*****************snacks method **************/
/****************showbalance method*******************/
public static double showbalance(double sumCoininsert, double price)
{
double price = 1.2, balance = 0, sumCoininsert;
balance = sumCoininsert - price;
if (balance != 0.00)
{
countbalance (balance);
System.out.println(" Your balance is :" +balance)
System.out.println(" :" +fifty+ "x50" " " +twenty+ "x20" " " +tenth+ "x10" );
}
else //if (balance == 0.00)
{
System.out.println("Your balance is :" +balance);
}
}
/****************balance method*******************/
/****************countbalance method******************/
public static double countbalance(double balance)
{
double balance;
int ibalance = (int)(balance);
int fifty = ibalance/50;
int cfifty = ibalance%50;
int twenty = cfifty/20;
int ctwenty = cfifty%20;
int tenth = ctwenty/10;
int ctenth = ctwenty%10;
if ( fifty != 0)
{
coin[1]--;
}
if (twenty != 0)
{
coin[2]--;
}
if (tenth != 0)
{
coin[3]--;
}
}
/*************balance method*********************/
/************************contmethod*****************************/
public static String contmethod (char cont)
{
char cont;
Scanner sc = new Scanner(System.in);
System.out.println ("Do you want to continue? y/n :");
//input3 = in.readline();
cont = sc.charAt(0);
while (cont == 'y' || cont == 'Y')
{
continue ;
}
System.out.println("Thank You, Please come again.");
System.exit(0);
}
}
*****************************************************
//Coins.java

import java.util.Scanner;
public class Coins {
public static void main (String args[])
{
int coin[] = {5,5,5,5};
int coinInsert = 0;
//double sumCoininsert = 0;
showmenu(coin);
inputcoin(coinInsert, coin);
//showbalance(sumCoininsert, price);
}
public static void showmenu (int coin[])
{
//System.out.println("[Coins available : RM 1 [" + coin[0] + "] RM0.50 [ " + coin[1] + "] RM 0.20 [ " + coin[2] + "] RM0.10 [" +coin[3] "] ]");
System.out.println("Coins available: RM1[" +coin[0]+ "]" + " RM0.50[" +coin[1]+ "]" + " RM0.20[" +coin[2]+ "]" + " RM0.10[" +coin[3] +"]");
}
/***********************inputcoin method *******************/
public static int inputcoin (int coinInsert, int coin[])
{
int sumCoininsert=0;
Scanner sc = new Scanner(System.in);
System.out.println("Insert Coin==>");
coinInsert = sc.nextInt();
while (coinInsert == 1 || coinInsert == 50 || coinInsert == 20 || coinInsert == 10)
{
//coinInc(coinInsert);
if (coinInsert == 1)
{
coin[0]++;
}else if (coinInsert == 50)
{
//double icoin = (int)(coin);
//ccoin = icoin/100;
coin[1]++;
}else if (coinInsert == 20)
{
//double icoin = (int)(coin);
//ccoin = icoin/100;
coin[2]++;
}else if (coinInsert == 10)
{
//double icoin = (int)(coin);
//ccoin = icoin/100;
coin[3]++;
} else
{
System.out.println("Invalid ");
sumCoininsert=0;
System.out.println("Insert Coin==>");
coinInsert = sc.nextInt();
}
sumCoininsert += coinInsert;
while (sumCoininsert < 120)
{
sumCoininsert = sumCoininsert + coinInsert;
System.out.println("Insert Coin==>");
coinInsert = sc.nextInt();
}
}
System.out.println (" Total Amount :" +sumCoininsert);
System.out.println("Available coins: RM1[" +coin[0]+ "]" + " RM0.50[" +coin[1]+ "]" + " RM0.20[" +coin[2]+ "]" + " RM0.10[" +coin[3] +"]");
return(0);
}