Answer:
Check the explanation
Step-by-step explanation:
import java.util.*;
public class VendingMachineAssignement {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
double item1 = 1.25;
double item2 = .75;
double item3 = .90;
double item4 = .75;
double item5 = 1.50;
double item6 = .75;
System.out.print("Enter an item number: ");
int item = keyboard.nextInt();
System.out.print("Enter the amount paid: ");
double paid = keyboard.nextDouble();
if (item == 2 || item == 4 || item == 6)
{
if (paid >= item2)
{
System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item2) + ". Please come again!");
}
if (paid < item2)
{
System.out.println("Please insert another " + "$" + (item2-paid));
}
}
else if (item == 1)
{
if (paid >= item1)
{
System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item1) + ". Please come again!");
}
if (paid < item1)
{
System.out.println("Please insert another " + "$" + (item1-paid));
}
}
else if (item == 3)
{
if (paid >= item3)
{
System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item3) + ". Please come again!");
}
if (paid < item3)
{
System.out.println("Please insert another " + "$" + (item3-paid));
}
}
else if (item == 5)
{
if (paid >= item5)
{
System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item5) + ". Please come again!");
}
if (paid < item5)
{
System.out.println("Please insert another " + "$" + (item5-paid));
}
}
}
}