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("密码不一致");
}



}
}







  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值