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

Create a program that simulates a vending machine -your program will ask the use

ID: 3585919 • Letter: C

Question

Create a program that simulates a vending machine -your program will ask the user to enter a price for an item first, then enter the amount of money deposited. Your program should display the change that is given to the user, as a number of quarters, dimes, nickels, and pennies. Change should be given using the smallest number of coins possible (change higher than 1 dollar can be given in quarters). If the user will receive no change, say "no change" instead of O quarters, 0 dimes, 0 nickels and O pennies. If the user enters less money than the price of the item then give an error message stating "not enough money inserted" with an error icon. After each transaction, whether enough money or not, ask the user if they have another transaction, using yes and no buttons, and repeat if so. Use JoptionPane for all inputs/outputs (no Scanner or println). Note: You can assume that the user will type the price as a decimal number without a dollar sign.

Explanation / Answer

Please find the code below

package com.chegg;

import javax.swing.JOptionPane;

public class VedningMachine {

public static void main(String[] args) {

String repeat="";

double price=0.0;

double amount=0.0;

double change=0.0;

String priceques ="";

String amountques="";

do{

priceques = JOptionPane.showInputDialog(null, "Enter Price of first item");

price = Integer.parseInt(priceques);

amountques = JOptionPane.showInputDialog(null, "Enter amount of money deposited");

amount = Integer.parseInt(amountques)+change;

if(amount<price){

JOptionPane.showMessageDialog(null, "Please enter more amount than price of item");

}else{

change = amount-price;

double quarterCents = change*25;

JOptionPane.showMessageDialog(null, "Chnage "+quarterCents+" Quarters");

repeat = JOptionPane.showInputDialog(null, "You want another transaction Yes or No");

JOptionPane.showMessageDialog(null, "Chnage "+repeat+" Quarters");

if(repeat.equals("no")){

break;

}else{

continue;

}

}

}while(repeat!="no");

//JOptionPane.showMessageDialog(null, "You have " + ans + " Things.");

}

}

I have placed change as quarters only

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