previous | start | next

Input/Output Example with JOPtionPane

import javax.swing.JOptionPane;

/**
 * A class to test the CashRegister class.
 */
public class CashRegisterTester2 {
  public static void main(String[] args) {
    CashRegister register = new CashRegister();
    double price1, price2, payment, change;

    String reply;
    reply = JOptionPane.showInputDialog("Price for first item:");
    price1 = Double.parseDouble(reply);

    reply = JOptionPane.showInputDialog("Price for second item:");
    price2 = Double.parseDouble(reply);

    reply = JOptionPane.showInputDialog("Payment amount:");
    payment = Double.parseDouble(reply);
    
    register.recordPurchase(price1);
    register.recordPurchase(price2);
    register.enterPayment(payment);

    change = register.giveChange();

    JOptionPane.showMessageDialog(null, "Your change is " + change);
            
    System.exit(0);
  }
}


previous | start | next