62,614
社区成员
发帖
与我相关
我的任务
分享
import javax.swing.JOptionPane;
public class SendGiftMenu {
public static void main(String[] args) {
int i; //顾客输入菜单编号
Content c = new Content();
c.getAsterisk();
c.getGiftMenu();
c.getAsterisk();
String str = JOptionPane.showInputDialog("请按菜单选择");
i = Integer.parseInt(str);
switch(i) {
case 1: JOptionPane.showMessageDialog(null, "幸运大放送"); break;
case 2: JOptionPane.showMessageDialog(null, "幸运抽奖"); break;
case 3: JOptionPane.showMessageDialog(null, "生日问候"); break;
default :JOptionPane.showMessageDialog(null, "请输入1~3其中之一的数字,谢谢合作");
}
}
}
class Content {
void getAsterisk() { //输出星号
for(int i=1;i<=30;i++){
System.out.print('*');
}
System.out.println();
}
void getGiftMenu() { //输出抽奖内容
System.out.println("1. 幸运大放送\n2. 幸运抽奖\n3. 生日问候");
}
}
int i = 0;
...
while (i == 0) {
i = Integer.parseInt(str);
switch(i) {
case 1: JOptionPane.showMessageDialog(null, "幸运大放送"); break;
case 2: JOptionPane.showMessageDialog(null, "幸运抽奖"); break;
case 3: JOptionPane.showMessageDialog(null, "生日问候"); break;
default :JOptionPane.showMessageDialog(null, "请输入1~3其中之一的数字,谢谢合作"); i = 0;
}
}