购物登录系统
package com.qingdaoligong.jierui; public class Start { //购物类
boolean result; public void window(){ System.out.println("欢迎使用我心我塑购物管理系统"); System.out.println("1.登录系统"); System.out.println("2.退出"); } public boolean scanner(String name,String password){ if(!name.equals("bird")||!password.equals("0000")){ result=true; }else{ result=false; } return result; } }
package com.qingdaoligong.jierui; import java.util.Scanner; public class StartTest { //测试类 public static void main(String[] args) { Start sms=new Start(); Scanner input=new Scanner(System.in); String name; String password; String Y="n"; do{ Y="n"; sms.window(); System.out.println("输入选项1or2:"); int shuzi=input.nextInt(); switch(shuzi){ case 1: System.out.println("请输入名称:"); name = input.next(); System.out.println("请输入密码:"); password = input.next(); boolean result = sms.scanner(name, password); if(result){ System.out.println("账户或密码错误,请重新登录:"); System.out.println("输入‘y’继续"); Y=input.next(); }else{ System.out.println("登录成功"); } break; case 2: System.out.println("退出"); break; default : System.out.println("叫你输入1或2,是不是傻"); } }while(Y.equals("y")); input.close(); } }