JAVA-1.6-homework
package study; import java.util.*; public class menu { int i; String [][]uname=new String[100][2]; String [][]upwd=new String[100][2]; public void mainMenu() { Scanner input = new Scanner(System.in); System.out.println("**********请先完成注册!**********"); System.out.println("1.登录"); System.out.println("2.注册"); System.out.println("3.幸运抽奖,输入四位会员卡号,如果百位等于系统随机数,就是星运会员.否则不是."); System.out.println("4.看小故事,"); System.out.println("5.退出系统"); System.out.println("请选择"); int i = input.nextInt(); switch (i) { case 1: login(); break; case 2: logon(); break; case 3: luck(); break; case 4: story(); break;
case 5:
break; } } private void login() { int x=0; String a,b; a=uname[i][0]; b=upwd[i][1]; System.out.println("**********登录**********"); Scanner input = new Scanner(System.in); System.out.println("输入用户名"); String uname = input.next(); System.out.println("输入密码"); String upwd = input.next(); for ( i = 0; i < this.uname.length; i++) { if (uname.contentEquals(a) && upwd.contentEquals(b)) { x=0; } else { x=1; } } if (x==0) { System.out.println("登录成功"); } else { System.out.println("登录失败"); } returnMain(); } public void logon() { System.out.println("**********注册**********"); System.out.print("请设置用户名:"); setuname(); System.out.print("请设置用户密码:"); setupwd(); System.out.println("设置成功!"); returnMain(); } public void setuname() { Scanner input = new Scanner(System.in); String name=input.next(); for ( i = 0; i < 100; i++) { if(uname[i][0]==null) { uname[i][0]=name; break; } } } public void setupwd() { Scanner input = new Scanner(System.in); for ( i = 0; i < 100; i++) { if(upwd[i][0]==null) { upwd[i][1]=input.next(); break; } } } public void luck() { System.out.println("**********幸运抽奖**********"); Random r=new Random(); int []a=new int[1]; for (int i = 0; i < a.length; i++) { a[i]=r.nextInt(9); } System.out.print("请输入会员号:"); Scanner input =new Scanner(System.in); int n=input.nextInt(); n=(n/100)%10; if(n==a[i]) { System.out.println("恭喜你成为本店幸运会员,请到前台领取奖品!谢谢你的惠顾!"); }else { System.out.println("很抱歉,你没有抽到幸运会员,谢谢你的惠顾!"); } returnMain(); } public void story() { System.out.println("**********看小故事**********"); Scanner input = new Scanner(System.in); System.out.println("1.美人鱼"); System.out.println("2.龙猫"); System.out.println("3.麻姑"); int i = input.nextInt(); switch (i) { case 1: System.out.println("在浩瀚的大海深处,王国最小的美人鱼公主善良纯洁,\n" + "心中充满了对陆地世界的憧憬和渴望。终于,美人鱼公主在生日\n" + "时游到海面上,恰好碰到乘船的人类王子不幸遭到暴风雨的袭击落\n" + "入海中,她奋不顾身的救起了王子,同时爱上了王子。"); break; case 2: System.out.println("该片讲述了草壁达郎的妻子草壁靖子生病住院后,他带着\n" + "草壁皋月与四岁的妹妹草壁米回到乡间居住的故事"); break; case 3: System.out.println("一天,麻姑在一户人家做好针线活,主人很满意,赏了一\n" + "个大桃子给她。古时候,桃子在水果中是上品,麻姑舍不得吃,把桃\n" + "子揣在怀里,想拿回家与父亲一起尝尝鲜。"); break; } returnMain(); } public void returnMain(){ System.out.println("是否返回主菜单?Y/N"); Scanner input = new Scanner(System.in); if (input.next().equalsIgnoreCase("Y")) { mainMenu(); }else{ System.out.println("谢谢使用"); } } }
package study; public class menutest { public static void main(String[] args) { menu m=new menu(); m.mainMenu(); } }
package study; //2.编写一个方法,求整数n的阶乘,例如5的阶乘是1*2*3*4*5。 [必做题] public class factorial { public static void main(String[] args) { fact(5); } public static void fact(int x) { int f=1; for (int i = 1; i <= x; i++) { f=f*i; } System.out.println("the end="+f); } }
package study; //3.编写一个方法,判断该年份是平年还是闰年。[必做题] public class factorial { public static void main(String[] args) { year(2020); } public static void year(int year) { if((year%4==0&&year%100!=0)||year%400==0) { System.out.println("这是一个闰年。"); }else { System.out.println("这是一个平年。"); } } }