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

Design an applet in Java. The applet should be a snack machine. The snack machin

ID: 3822586 • Letter: D

Question

Design an applet in Java. The applet should be a snack machine. The snack machine should dispense 3 varieties of chips $0.65, 5 varieties of drinks $1.25 and 4 varieties of cookies/crackers $0.75.
When the applet starts, the snack machine should have a supply of 20 of each of the five different types of drinks. Twenty of the three differnt types of drinks.  And twenty of each of the four varieties of cookies/crackers.   The applet should have a text field where the user can enter the amount of money he or she is giving the machine. The user can then click on a button to select the products to dispense. The applet should also display the amount of change it is giving back to the user. The applet should keep track of its inventory of products and inform the user if he or she has selected items or item is out of stock. Be sure to handle operator errors such as selecting a product  without entering in money or selecting a product with incorrect amount of money.

Explanation / Answer

import.java.util.scanner;
public class SnackMac
{
public static void main (String args[])
{
int[4] insert_Coin = {5,5,5,5};
int[4] drink_Out = {5,5,5,5};
int ch;
char proc;

double total_price = 1.2, bal = 0, putting_Coin = 0, sum_of_coins = 0;
display_menu(insert_Coin, drink_Out);
sum_of_coins = coin_inputs(putting_Coin);
display_of_drinks(ch);
show_balnc(sum_of_coins, total_price);
deciding_Way(proc);
}

public static int display_menu (int insert_Coin, int drink_Out)
{
int insert_Coin;
int drink_Out;
System.out.println("[Coins available : RM 1 [" + insert_Coin[0] + "] RM0.50 [ " + insert_Coin[1] + "] RM 0.20 [ " + insert_Coin[2] + "] RM0.10 [" +insert_Coin[3] "] ]");
System.out.println("[Drinks available : Thums UP [" + drink_Out[0] + "] Sprite [" + drink_Out[1] + "] Fanta [" + drink_Out[2] + "] Appy [" + drink_Out[3] + "] ]");
}


public static double coin_inputs (double putting_Coin)
{
double putting_Coin = 0, sum_of_coins = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Please insert a coin in the machine==>");
double putting_Coin = sc.nextDouble();
while (putting_Coin == '1' || putting_Coin == '0.5' || putting_Coin == '0.2' || putting_Coin == '0.1')
{
coinInc(putting_Coin);
sum_of_coins = sum_of_coins + putting_Coin;
while (sum_of_coins < 1.20)
{
System.out.println("Insert insert_Coin==>");
double putting_Coin = sc.nextDouble();
}
}
System.out.println (" Total :" +sum_of_coins);
}

public static double coinInc(int putting_Coin)
{
double putting_Coin;
Scanner sc = new Scanner(System.in);
switch (putting_Coin) {
case putting_Coin == '1':
insert_Coin[0]++;
break;
case putting_Coin == '0.5':
insert_Coin[1]++;
break;
case putting_Coin == '0.2':
insert_Coin[2]++;
break;
case putting_Coin == '0.1':
insert_Coin[3]++;
break;
default:
System.out.println("Invalid insert_Coin");
sum_of_coins = 0;
System.out.println("Insert insert_Coin==>");
double putting_Coin = sc.nextDouble();
break;
}
}

public static int display_of_drinks (int ch)
{
int ch;
System.out.println("Snacks Machine");
System.out.println("1.Thums UP" " 2.Sprite" " 3.Fanta" " 4.Appy");
Scanner sc = new Scanner(System.in);
System.out.println("ch==>");
int ch = sc.nextInt();
while (ch == '1' || ch == '2' || ch == '3' || ch == '4')
{
if (ch =='1')
{
drink_Out[0]--;
}else if (ch=='2')
{
drink_Out[1]--;
}else if (ch =='3')
{
drink_Out[2]--;
}else (ch == '4')
{
drink_Out[3]--;
}
}
System.out.println("Invalid ch");
System.out.println("ch==>");
int ch = sc.nextInt();
}

public static double showbalance(double sum_of_coins, double total_price)
{
double total_price = 1.2, bal = 0, sum_of_coins;
bal = sum_of_coins - total_price;
if (bal != 0.00)
{
countbalance (bal);
System.out.println(" Your bal is :" +bal)
System.out.println(" :" +bal_fifty+ "x50" " " +bal_twenty+ "x20" " " +bal_tenth+ "x10" );
}else //if (bal == 0.00)
{
System.out.println("Your bal is :" +bal);
}
}

public static double countbalance(double bal)
{
double bal;
int bal_hold = (int)(bal);
int bal_fifty = bal_hold/50;
int bal_cfifty = bal_hold%50;
int bal_twenty = bal_cfifty/20;
int bal_ctwenty = bal_cfifty%20;
int bal_tenth = bal_ctwenty/10;
int bal_ctenth = bal_ctwenty%10;
if ( bal_fifty != 0)
{
insert_Coin[1]--;
}
if (bal_twenty != 0)
{
insert_Coin[2]--;
}
if (bal_tenth != 0)
{
insert_Coin[3]--;
}
}

public static String deciding_Way (char proc)
{
char proc;
Scanner sc = new Scanner(System.in);
System.out.println ("Wish to continue? y/n :");
//input3 = in.readline();
proc = sc.charAt(0);
while (proc == 'y' || proc == 'Y')
{
continue ;
}
System.out.println("Thank You, Visit us Again");
System.exit(0);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote