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: 3777026 • 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 I just need a gui java code ty y'all are lifesavers

Explanation / Answer

import.java.util.scanner;

public class VendingMachine

{

public static void main (String args [ ])

{

int[4] coin = { 5, 5, 5, 5};

int[4] drink = {5, ,5, 5, 5}; //array that hold beverages values

int choice;

char cont;

//String input1, input2, input3;

double price = 1.2, balance =0, coinInsert =0, sumCoinInsert =0;

showmenu(coin, drink);

sumCoininsert = inputcoin(coinInsert);

showdrinks(choice);

showbalance(sumCoininsert, price);

contmethod(cont);

}

/* show mwthod */

public static int showmenu (int coin, int drink)

{

int coin;

int drink;

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("Beverages available : pepsi ["+drink[0] + "] coke [" + drink[1] + "] Mirinda Orange [" +drink[2] + "] 7up [" +drink[3] + "] ]");

}

public static double inputcoin (double coinInsert)

{

double coinInsert = 0, sumCoininsert = 0;

scanner sc = new Scanner(System.in);

System.out.println("Inner 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 && (coinInsert == '1' || coinInsert == '0.5' | coinInsert == '0.2' || coinInsert == '0.1' ) )

{

System.out.println("Insert Coin==>");

double coinInsert = sc.nextDouble();

sumCoininsert = sumCoininsert + coinInsert ;

}

}

System.out.println("Total :" +sumcoinInsert);

}

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;

}

}

/* beverages method */

public static int shoedrinks ( int choice)

{

int choice;

System.out.println("beverages [RM1.20]");

System.out.println("1.pepsi" " 2.coke" " 3.Mirinda orange" " 4.7up);

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' )

{

drink[0] --;

}

else if (choice=='2' )

{

drink [1 ] --;

} else if (choice == '3')

{

drink[2]-- ;

}else (choice =='4')

{

drink[3] --;

}

}

System.out.println("Invalid choice");

System.out.println("choice==>");

int choice = sc.nextInt();

}

/* shoe balance */

public static double showbalance(double sumCoin, double price)

{

double price =1.2, balance =0, sumCoininsert ;

balance + sumCoininsert -price ;

if 9balance != 0.00)

{

countbalance (balance);

System.out.println("Your balance is :" +balance)

System.out.println(" :" =fifty+ "x50" " " +twenty + "x20" " " +tenth+ "x10" ) ;

}

else

{

System.out.println("Your balance is:" +balance) ;

}

}

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]--;

}

}

public static String contmethod ( char cont)

{

char cont ;

Scanner.out.println ("Do you want to continue? y/n : " ) ;

cont = sc.charAt( 0 ) ;

while (cont == 'Y' || cont == 'y')

{

continuec;

}

System.out.println("thank you");

System.exit( 0);

}

}