今天复习后所敲的代码.
public class Scuog {
String name;
int age;
public void show() {
Scanner input = new Scanner(System.in);
while (!"n".equals(name)) {
if (age >= 14 && age <= 60) {
System.out.println(name + "的年龄为:" + age + ",门票价格为:20万元\n");
} else {
System.out.println(name + "的年龄为:" + age + ",门票免费\n");
}
System.out.println("(输入n退出购买)请输入姓名:");
name = input.next();
if (!"n".equals(name)) {
System.out.println("(输入n退出购买)请输入年龄:");
}
}
System.out.println("退出程序");
}
}
public class Scuog2 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
Scuog a=new Scuog();
System.out.println("(为n退出购买)请输入姓名:");
a.name=input.next();
System.out.println("(为n退出购买)请输入你的年龄:");
a.age =input.nextInt();
a.show();
}
}
public class Stoed {
public static void main(String[] args) {
String yes;
String mayin = null;
String mima;
int suzi = 0;
boolean zhuce = false;
boolean doute = false;
int max = 9999;
int min = 1000;
do {
System.out.println("*****欢迎进入奖客富翁系统*****");
System.out.println("\t1.注册");
System.out.println("\t2.登入");
System.out.println("\t3.抽奖");
System.out.println("********************************");
System.out.print("请选择菜单:");
Scanner input = new Scanner(System.in);
int so = input.nextInt();
switch (so) {
case 1:
System.out.println("[奖客富翁系统> 注册]");
System.out.println("请输入个人信息:");
System.out.print("用户名:");
mayin = input.next();
System.out.print("密码:");
mima = input.next();
suzi = (int) (Math.random() * (max - min)) + min;
System.out.println("\n注册成功,请记好您的卡号");
System.out.println("用户名\t 密码\t 会员卡号");
System.out.println(mayin + "\t" + mima + "\t " + suzi);
zhuce = true;
break;
case 2:
if (zhuce) {
for (int i = 1; i <= 3; i++) {
System.out.println("[奖客富翁系统> 登入]");
System.out.print("请输入用户名:");
String names = input.next();
System.out.print("请输入密码:");
String pwds = input.next();
if (mayin.equals(names) && mayin.equals(pwds)) {
System.out.println("欢迎您:" + mayin);
doute = true;
break;
} else if (i < 3) {
System.out.println("用户名或密码错误,你还有" + (3 - i) + "次机会");
} else {
System.out.println("您3次输入密码或用户名都错误!");
}
}
} else {
System.out.println("请先注册,再登入!");
}
break;
case 3:
System.out.println("[奖客富翁系统> 抽奖]");
if (!doute) {
System.out.println("请先登入,再抽奖!");
System.out.print("继续吗?(y/n):");
yes = input.next();
} else {
int[] nums = new int[5];
for (int i = 0; i < nums.length; i++) {
nums[i] = (int) (Math.random() * (max - min)) + min;
}
System.out.print("请输入您的卡号:");
int Cards = input.nextInt();
System.out.println("\n本期幸运数字为:");
int j;
for (j = 0; j < nums.length; j++) {
System.out.print(nums[j] + " ");
}
for (j = 0; j < nums.length; j++) {
if (nums[j] == suzi) {
System.out.println("\n恭喜!您是本期的幸运会员!");
break;
}
}
if (j == nums.length) {
System.out.println("\n抱歉,您不是本期的幸运会员!");
}
}
break;
default:
System.out.println("您的输入有误!");
break;
}
System.out.print("继续吗?(y/n):");
yes = input.next();
System.out.println("");
} while ("y".equals(yes));
if ("n".equals(yes)) {
System.out.println("系统退出,谢谢使用!");
}
}
}