1、创建Login类
2、创建TestLogin类
import java.util.Scanner;
public class Login {
String name; //账号
String pwd; //密码
/**
* @param args
*/
public void Login() {
// 输出出菜单
System.out.println("\t欢迎进入经销商系统");
System.out.println("\t1、登陆系统");
System.out.println("\t2、退出");
System.out.println("请输入要进入的菜单:");
boolean con;
do{
Scanner input=new Scanner(System.in);
con=false;
int no=input.nextInt();
if(no==1){
input();
}else if(no==2){
Send();
con=true;
}
}while(con);
}
public void input(){
Scanner input=new Scanner(System.in);
System.out.println("请输入账号");
String name=input.next();
System.out.println("请输入密码");
String pwd=input.next();
if("lyg".equals(name)&&"abc123..".equals(pwd)){
System.out.println("登陆成功");
System.out.println("*****************************************");
System.out.println("\n\t欢迎登陆经销商系统");
System.out.println("\t 1.客户信息维护");
System.out.println("\t 2.客户信息查询");
System.out.println("\t 3.客户信息修改");
System.out.println("输入0退出系统:");
int no=input.nextInt();
if(no==0){
Send();
}else{
System.out.println("输入错误结束。");
}
}else{
System.out.println("密码错误,请重新登陆");
input();
}
}
public void Send(){
System.out.println("系统已退出,欢迎下次在使用");
}
}
-------------------------------------------
import java.util.Scanner;
public class TestLogin {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Login l=new Login();
l.Login();
Scanner input=new Scanner(System.in);
int choice=input.nextInt();
switch(choice){
case 1:
l.Login();
case 2:
l.Send();
}
}
}