java -基于控制台显示的电子商城之单用户登录

package shop1;


import java.util.Scanner;


public class ConsoleShop {
Scanner sc = new Scanner (System.in);
String password;
String username;
public static void main(String[] args) {
// TODO Auto-generated method stub
ConsoleShop shop = new ConsoleShop();
shop.showMainMenu1();
shop.showMainMenu();

}
private void showMainMenu1(){
System.out.println("****************欢迎进入电子商城****************");
System.out.println("\t1.注册");
System.out.println("\t2.登录");
System.out.println("\t3.查看商店");
System.out.println("\t4.查看购买的商店");
System.out.println("\t5.管理员登录");
System.out.println("\t6.退出系统");
System.out.println("**********************************************");
}

private void showMainMenu(){
boolean is_go_on = true;
System.out.println("请输入您的选项:");

while(is_go_on = true) {
int choice = sc.nextInt(); //整型
if(choice==1){
System.out.println("您选择的是:1.注册");
//System.out.println("欢迎注册");
//System.out.println("请输入用户名:");
this.reg();//调用方法

}
else if(choice==2){
System.out.println("您选择的是:2.登录");
this.login();

}
else if(choice==3){
System.out.println("您选择的是:3.查看商店");
}
else if(choice==4){
System.out.println("您选择的是:4.查看购买的商店");
}
else if(choice==5){
System.out.println("您选择的是:5.管理员登录");
}
else if(choice==6){
System.out.println("谢谢使用");  
is_go_on = false;
break;
   }
else 
System.out.println("输入有误,请重新输入");

}
}

private void login() { //登录
// TODO Auto-generated method stub
System.out.println("欢迎登录");
System.out.println("请输入用户名:");
String login_username = sc.next();
System.out.println("请输入密码:");
String login_password = sc.next();

if((login_username.equals(username))&&(login_password.equals(password))) //判断登录账号密码与注册账号密码是否一致
{
System.out.println("登录成功");
}
else
{
System.out.println("登录失败");
}
}



private void reg() { //注册
// TODO Auto-generated method stub
System.out.println("欢迎注册");
System.out.println("请输入用户名:");
String username = sc.next();
while(true){
System.out.println("请输入密码:");
String password = sc.next();
System.out.println("再次输入密码:");
String repassword = sc.next();
if(password.equals(repassword)){  //判断密码是否一致
System.out.println("注册成功");
break;//成功后退出循环
}
else
System.out.println("密码不一致");
}



}
}







猜你喜欢

转载自blog.csdn.net/qq_42183409/article/details/80385216
今日推荐