public class member { public String phone; public String pass; public member(){} public member(String phone,String pass) { this.phone=phone; this.pass=pass; }}import java.util.HashSet;import java.util.Set;public class people { public String phone; public String pass; public Set<member> members; public people(String phone,String pass) { this.phone=phone; this.pass=pass; this.members=new HashSet<member>(); }}import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.Scanner;import org.omg.CORBA.PUBLIC_MEMBER;public class test { public static List<member> gaMembers; public test() { this.gaMembers=new ArrayList<member>(); } public void add() { member m1=new member("111", "123"); gaMembers.add(m1); member[] m2={new member("qqq", "qqw"),new member("wo", "gjj")}; gaMembers.addAll(Arrays.asList(m2)); } public void foreach() { for(member mc:gaMembers) { System.out.println("会员信息:"+mc.phone+" , "+mc.pass); } } public static void main(String[] args) { test t1=new test(); t1.add(); people p1=new people("1", "x小明"); System.out.println("****欢迎进入系统****"); System.out.println("登录请按1,注册请按2"); Scanner input=new Scanner(System.in); int a=input.nextInt(); if(a==1) { System.out.println("请输入账号:"); String b=input.next(); System.out.println("请输入密码:"); String c=input.next(); for (member mm: t1.gaMembers) { if(mm.phone.equals(b) && mm.pass.equals(c)) { System.out.println("登录成功!请进入游戏"); int num1=(int)(Math.random()*100); int n1=num1/10; int n2=num1%10; int num2=(int)(Math.random()*100); int n3=num2/10; int n4=num2%10; int num=num1*100+num2; System.out.println("请随机输入四个数:"); int x1=input.nextInt(); int x2=x1/1000; int x3=(x1/100)%10; int x4=(x1/10)%100; int x5=x1%1000; System.out.println("中奖数字为:"+num); if (x1==num) { System.out.println("恭喜获得一等奖!"); } else if (n1==x2 &&n2==x2 && n3==x3) { System.out.println("恭喜获得二等奖!"); } else if (n1==x2 &&n2==x2) { System.out.println("恭喜获得三等奖!"); } else { System.out.println("不中奖!"); } } else { System.out.println("账号或密码错误!请重新输入"); } } } else { System.out.println("请输入注册账号:"); String d=input.next(); System.out.println("请输入注册密码:"); String e=input.next(); member m3=new member(d, e); gaMembers.add(m3); for(member mm:gaMembers) { p1.members.add(m3); } System.out.println("你的会员信息为:"); t1.foreachset(p1); System.out.println("注册成功!请重新登录"); } } public void foreachset(people p1) { for(member cc:p1.members) { System.out.println(cc.phone+","+cc.pass); } } }/** 1. System.out.println("账号或密码错误!请重新输入");这一句代码总是重复执行。 2. 进入注册,注册成功后该怎样重新返回到登录时账号密码的输入界面?难道要把那段登录的代码复制到注册成功后面而不能用循环或者什么重新返回到那个位置上吗?
添加回答
举报
0/150
提交
取消