JAVA实现菜单的级联效果

1、先创建Lyg类

2、分别编写方法,实现功能

3、创建TestLyi类,进行验证

import java.util.Scanner;
public class Lyg {
    public  void Login(){
        System.out.println("\n\t\t欢迎使用经销商系统\n");
        System.out.println("\t1.登陆系统\n");
        System.out.println("\t2.退出\n");
        System.out.println("*****************************************");
        System.out.println("请选择输入数字:");
    }
    public void Main(){
        boolean con;
        System.out.println("\n\t欢迎登陆经销商系统");
        System.out.println("*****************************************");
        System.out.println("\t\t 1.客户信息管理\n");
        System.out.println("\t\t 2.真情回馈\n");
        System.out.println("*****************************************");
        System.out.println("请输入数字:");
        do{
            con=false;
            Scanner input=new Scanner(System.in);
            int no=input.nextInt();
            if(no==1){
                Cust();
            }else if (no==2){
                Send();
            }else if(no==0){
                Login();
            }else{
                System.out.print("输入错误,请重新输入");
                con=true;
            }
        }while(con);
    }
    public void Cust(){
        System.out.println("*****************************************");
        System.out.println("\t1、查询客户信息");
        System.out.println("\t2、修改客户信息");
        System.out.println("\t3、添加客户信息");
        System.out.println("\t4、显示所有客户信息");
        System.out.println("*****************************************");
        System.out.println("输入数字\n0、返回上一层\n1、返回主菜单\n2、进入真情回馈");
        boolean con;
        do{
            con=false;
            Scanner input=new Scanner (System.in);
            int no=input.nextInt();
            if(no==0){
                Main();
            }else if(no==1){
                Login();
            }else if(no==2){
                Send();
            }
        }while(con);
        
        
    }
    public void Send(){
        System.out.println("*****************************************");
        System.out.println("1、普卡会员抽奖");
        System.out.println("2、银卡会员抽奖");
        System.out.println("3、金卡会员抽奖");        
        System.out.println("*******************************");
        System.out.println("输入要执行的抽奖活动:");
        boolean con;
        do{
            con =false;
            Scanner input=new Scanner(System.in);
            int no =input.nextInt();
            if(no==1){
                System.out.println("普卡会员抽奖");
            }else if(no==2){
                System.out.println("银卡会员抽奖");
            }else if(no==3){
                System.out.println("金卡会员抽奖");
            }else if(no==0){
                Main();
            }else{
                System.out.println("输入错误,请重新输入数字:");
                con=true;
            }
        } while(con);
    }

}
-------------------------------

2、在创建TestLyi类

import java.util.Scanner;
public class TestLyi {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        Lyg menu=new Lyg();
        menu.Login();
        boolean con=true;
        do{
            int choice=input.nextInt();
            switch(choice){
            case 1:
                menu.Main();
                break;
            case 2:
                System.out.println("感谢您的使用");
                con=false;
                break;
                
            }
        }while(con);

    }

}
 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值