Back to Examples
package edu.iuk.MailOrder;

import javax.swing.JOptionPane;

public class MailOrder {

  public static void main(String[] args) {

    // Jacob Morris
    int productNum = 1;
    int productSold;
    double oneCost = 0;
    double twoCost = 0;
    double threeCost = 0;
    double fourCost = 0;
    double fiveCost = 0;

    while (!(productNum == 0)) {

      productNum = Integer.parseInt(JOptionPane.showInputDialog(“enter product number(1-5)(0 to stop):”));

      if (productNum != 0) {
        productSold = Integer.parseInt(JOptionPane.showInputDialog(“Please enter number of products sold”));

        if (productNum == 1) {

          oneCost += 2.98 * productSold;

        } else if (productNum == 2) {

          twoCost += 4.5 * productSold;

        } else if (productNum == 3) {

          threeCost += 9.98 * productSold;

        } else if (productNum == 4) {

          fourCost += 4.49 * productSold;

        } else if (productNum == 5) {

          fiveCost += 6.87 * productSold;

        }

      }

    }

    JOptionPane.showMessageDialog(null, “product 1: ” + oneCost + “\nproduct 2: ” + twoCost + “\nproduct 3: ” + threeCost + “\nproduct 4: ” + fourCost + “\nproduct 5: ” + fiveCost);
  }

}
Back to Examples

Startup Discount
Small Business?
Contact us for an Enormous Discount!