/******
This example shows how to display multiple lines in a dialog box
******/
import javax.swing.*;
public class DisplayMultipleLinesOnJOptionPane {
public static void main(String[] args) {
String inputStr;
inputStr = JOptionPane.showInputDialog(null,
"What drink you want?\n1)Coffee\n2)Tea\n3)Coke");
// Convert the input to an int
int drink = Integer.parseInt(inputStr);
inputStr = JOptionPane.showInputDialog(null,
"How many cups?");
int cups = Integer.parseInt(inputStr);
double costofdrink=0;
switch(drink){
case 1:
costofdrink = 0.50;
break;
case 2:
costofdrink = 0.60;
break;
case 3:
costofdrink = 1.00;
break;
} //end drink
JOptionPane.showMessageDialog(null,
"You ordered " + cups
+ " of drinks.\n"
+ "Total cost is : "+
+ costofdrink*cups);
} //end main
} //end class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment