You are on page 1of 3

/* * Author:James Andrew Diana * Description:Vending Machine using JOptionPane * DueDate:9/20/12 */ import javax.swing.JOptionPane; import java.text.

DecimalFormat; public class vender { public static void main(String[] args) { //Process output dialog String cmoney = JOptionPane.showInputDialog("Please insert money amount " + "\n 1 : coke = $1.25" + "\n 2 : Sprite = $1.50" + "\n 3 : Dr. Pepper = $2.00" + "\n 4 : Fanta Orange =$2.25"); String soda = JOptionPane.showInputDialog("You have inserted: $"+cmoney + "\nPlease select the number cooresponding to your soda selection " + "\n 1 : coke = $1.25" + "\n 2 : Sprite = $1.50" + "\n 3 : Dr. Pepper = $2.00" + "\n 4 : Fanta Orange =$2.25"); //Declaration Integer Isoda = Integer.parseInt(soda); Double Dcmoney = Double.parseDouble(cmoney); DecimalFormat twodec = new DecimalFormat("0.00"); double r=0; (Dcmoney > 5) { JOptionPane.showMessageDialog(null, "Can not accept more than $5 \nPlease insert a smaller amount and try again"); } else if (Isoda <1 || Isoda>4) { JOptionPane.showMessageDialog(null, "Your selected soda is not an optional selection \nPlease try again"); } if (Dcmoney <= 5) { if (Isoda ==1 && Dcmoney == 1.25 || Isoda == 2 &&Dcmoney == 1.50 || Isoda == 3 && Dcmoney == 2.00 || Isoda == 4 && Dcmoney ==2.25) { JOptionPane.showMessageDialog(null,"Please pick up your bottle from the dispenser"); } else if

if (Isoda == 1 ) {if( Dcmoney > 1.25) { r = Dcmoney - 1.25; JOptionPane.showMessageDialog(null,"Your change is : $" + twodec.format(r) + "\nPlease pick up your bottle from the dispenser"); } else if( Dcmoney < 1.25) { r = 1.25 - Dcmoney; JOptionPane.showMessageDialog(null,"Insufficient funds. Please insert : $" + twodec.format(r) + " more and Try Again"); } } else if(Isoda == 2) {if(Dcmoney >1.50) { r = Dcmoney -1.50; JOptionPane.showMessageDialog(null,"Your change is : $" + twodec.format(r) + "\nPlease pick up your bottle from the dispenser"); } else if (Dcmoney < 1.50) { r = 1.50 - Dcmoney; JOptionPane.showMessageDialog(null,"Insufficient funds. Please insert : $" + twodec.format(r) + " more and Try Again"); } } else if(Isoda == 3) {if (Dcmoney > 2.00) { r = Dcmoney -2.00; JOptionPane.showMessageDialog(null,"Your change is : $" + twodec.format(r) + "\nPlease pick up your bottle from the dispenser"); } else if (Dcmoney < 2.00) { r = 2.00 - Dcmoney; JOptionPane.showMessageDialog(null,"Insufficient funds. Please insert : $" + twodec.format(r) + " more and Try Again"); } } else if(Isoda == 4) {if(Dcmoney >2.25) {

r = Dcmoney -2.25; JOptionPane.showMessageDialog(null,"Your change is : $" + twodec.format(r) + "\nPlease pick up your bottle from the dispenser"); } else if(Dcmoney<2.25) { r = 2.25 - Dcmoney; JOptionPane.showMessageDialog(null,"Insufficient funds. Please insert : $" + twodec.format(r) + " more and Try Again"); } } } } }