当前位置 : 主页 > 编程语言 > java >

欣知商城

来源:互联网 收集:自由互联 发布时间:2022-07-22
import java.util.Scanner; public class Nummanage1 { int useNem;//用户输入的号码 int winNum;//开奖号码 public Nummanage1() { this.useNem = -1;//初始值为-1 this.winNum = 98;//中奖号码为98 } //主界面 public void main() {
import java.util.Scanner;

public class Nummanage1 {
int useNem;//用户输入的号码 int winNum;//开奖号码 public Nummanage1() {
this.useNem = -1;//初始值为-1 this.winNum = 98;//中奖号码为98 }
//主界面 public void main() {
System.out.println("---------------------");
System.out.println("欢迎进入欣知商城");
System.out.println("请选择您的操作:1.开始选号 2.现在开奖 3.退出");
System.out.println("---------------------");

choose();
}
//方法 public void choose() {
System.out.println("请输入您的选择:");
Scanner scanner = new Scanner(System.in);
int choose = scanner.nextInt();
if (choose < 1 || choose > 3) {
System.out.println("您输入的号码有误,请重新输入:");
choose();
} else {
switch (choose) {
case 1:
xuanhao();
break;
case 2:
kaijiang();
break;
case 3:
tuichu();
break;
default:
System.out.println("无该选项,请重新选择");
main();
break;
}
}
}
public void xuanhao() { //选择号码 System.out.println("请输入您的号码,号码最多不能超过两位数:");
Scanner scanner = new Scanner(System.in);
useNem = scanner.nextInt();
if (useNem < 0 || useNem > 100) {
System.out.println("您输入的号码有误,请重新输入:");
xuanhao();
} else {
System.out.println("输入完毕,已返回主菜单:");
main();
}

}
//开奖 public void kaijiang(){
if(useNem==-1){
System.out.println("请重新输入:");
xuanhao();
} else{
if (useNem==winNum){
System.out.println("恭喜您中奖了");

} else{
System.out.println("很遗憾您没有中奖,您是否还要继续抽奖Y/N(Y继续 N退出)");
Scanner scanner = new Scanner(System.in);
String jixu = scanner.next();
switch (jixu){
case"y":
useNem=-1;
xuanhao();
break;
case "Y":
useNem=-1;
xuanhao();
break;
case "n":
tuichu();
break;
case "N":
tuichu();
break;
default:
System.out.println("按y/n");
kaijiang();
}
}
}
}
//退出界面 public void tuichu(){
System.out.println("欢迎下次来玩");
}

public static void main(String[] args) {
Nummanage1 nummanage1 = new Nummanage1();
nummanage1.main();
}
}
网友评论