java 案例 神灯客服

视频地址

https://www.ixigua.com/6791887025654989319?logTag=9dcc311cbbde04518292

分支图

 

程序实现思路

  1. 搭建平台

  2. 显示欢迎语句

  3. 显示选择语言界面

  4. 循环主菜单

  5. 打印功能菜单

  6. 打印二级功能菜单

  7. 接入客服

  8. 询问用户需不需要产品

  9. 输出工作时间并判断

中文平台

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;

public class GameCN {
    //扫描仪
    Scanner input = new Scanner(System.in);

    //用户输入的愿望
    String yw;

    //实例化英文菜单
    GameUS gameUS = new GameUS();

    public void game(){
        //显示欢迎语句
        wlecome();

        //循环显示主菜单
        runMian();
    }

    private void runMian() {
        //显示中文菜单
        int lan = showCNU();

        //循环
        menuLoop(lan);
        }

    private void menuLoop(int lan) {
        while (true){
            switch (lan){
                case 1:
                    CN();
                    break;
                case 2:
                    gameUS.game();
                    break;
            }

        }

}

    //用户选择
    private void userChoice() {
        System.out.println("请选择您要的服务:");
        int userchoice = input.nextInt();
        switch(userchoice){
            case 1:
                //祈祷
                QD();
                break;
            case 2:
                //诅咒
                ZZ();
                break;
            case 3:
                //实现愿望
                SXYW();
                break;
            case 4:
                //还愿
                HY();
                break;
            case 5:
                //高考分数查询
                GGFSCX();
                break;

            default:
                //如果用户非法输入, 返回主菜单
                System.out.println("非法输入!返回主菜单!");
                break;
        }
    }

    //高考分数查询
    private void GGFSCX() {
        System.out.println("运行高考分数查询!");
    }

    //还愿
    private void HY() {
        System.out.println("运行还愿!");
    }

    //实现愿望
    private void SXYW() {
        //显示功能菜单
        functionMenu();
        //用户输入功能
        userInput();
    }

    //用户输入功能
    private void userInput() {
        //用户输入需要的功能
        System.out.print("请选择您需要的功能:");
        int userChiose = input.nextInt();
        //分支
        switch(userChiose){
            case 1:
                //延年益寿
                YNYS();
                break;
            case 2:
                //盛世美颜
                SSMY();
                break;
            case 3:
                //强生健体
                QSJT();
                break;
            case 4:
                //升官发财
                SGFC();
                break;
            case 5:
                //找到爱情
                ZDAQ();
                break;
            case 8:
                //其他愿望
                QTYW();
                break;
            default:
                //如果用户非法输入, 返回主菜单
                System.out.println("非法输入!");
                System.out.println("返回主菜单!");
                break;
        }
    }

    //其他愿望
    private void QTYW() {
        System.out.println("运行其他愿望!");
        //接入客服
        customerService();
        //客服接入
        userInputDesire();
    }

    //客服接入
    private void userInputDesire() {
        //用户输入愿望
        System.out.println("客服已接入");
        System.out.println("请输入您的愿望:");
        yw = input.next();

        //询问用户是否加一元换购零食
        System.out.println("是否要加一元换购一袋方便面(y/n)?");
        String hg = input.next();

        //询问用用户是否要新出来的瓜子
        System.out.println("主人,我们退出了最新口味的麻辣味的瓜子是否需要呢(y/n)?");
        String gz = input.next();

        //询问用户是否要再许一个愿望换积分
        System.out.println("您许的愿望“"+yw+"“可以有6个积分,还差1个积分可以换取一个新的愿望,要不要再选一个凑够积分呢(y/n)?");
        String userInputYW = input.next();
        //判断用户是否在要一个愿望
        if (userInputYW.equals("y")){
            System.out.println("请输入您下一个愿望:");
            String yw02 = input.next();
        }

        //请问是否要办一张会员卡
        System.out.println("请问是否要办一张会员卡(y/n/b):");
        System.out.println("\t\ty.要办会员");
        System.out.println("\t\tn.不要办会员");
        System.out.println("\t\tb.把他痛扁一顿");
        String vip = input.next();

        //分支
        switch(vip){
            case "y":
                System.out.println("要办一张会员卡!");
                break;
            case "n":
                //询问是否是VIP
                noVip();
                break;
            case "b":
                System.out.println("把神灯痛扁一顿!");
                System.exit(0);
                break;
        }
    }

    //询问是否是VIP
    private void noVip() {
        //用户输入
        System.out.println("请问是否是VIP(y/n):");
        String vip = input.next();

        //判断
        if (vip.equals("y")){
            System.out.println("唉,不是VIP要开一段广告!");
            System.out.println("找工作...");
        }
        time();
    }

    //上班时间
    private void time() {
        System.out.println("你好,客服上班时间是:9:00 - 16:00");
        //调用时间对象
        Date date = new Date();
        //设置输出格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年 MM月dd日 HH时mm分ss秒");
        //录入时间
        String daytime = simpleDateFormat.format(new Date());
        //打印时间
        System.out.println("现在时间:"+daytime);

        //判断是否是工作时间

        //获取小时
        int workTime = date.getHours();
        //判断工作时间
        if (workTime >=9 && workTime<=16){
            System.out.println("现在是上班时间!");
            System.out.println("显示愿望!");
            return;
        }else{
            System.out.println("现在是下班时间!");
            System.out.println("请注意客服工作时间!");
            System.exit(0);
        }
    }

    //接入客服
    private void customerService() {
        System.out.println("正在转人工坐席...");
        while(true){
            //输出音乐
            System.out.println("啦啦啦...");

            //随机数
            Random random = new Random();

            //取随机数 0 - 3
            int randomNum = random.nextInt(3);

            //判断随机数是否为0,
            if (randomNum==0){
                //是的就接入客服
                System.out.println("等待成功,正在接入客服!");
                break;
            }else{
                //不是就询问用户是否等待

                //询问用户是否继续等待
                System.out.println("坐席全忙,是否继续等待:");
                System.out.println("\t\t1.继续等待");
                System.out.println("\t\t2.用户选择挂机");
                int userInput = input.nextInt();

                //判断
                if (userInput == 1){
                    //用户选择 1 继续循环
                    System.out.println("用户选择了继续等待!");
                }else if (userInput == 2){
                    //用户选择 2 退出系统
                    System.out.println("用户选择了挂机!");
                    System.exit(0);
                }
            }

        }
    }

    //找到爱情
    private void ZDAQ() {
        System.out.println("运行找到爱情!");
    }

    //升官发财
    private void SGFC() { System.out.println("运行升官发财!"); }

    //强身健体
    private void QSJT() {
        System.out.println("运行强生健体!");
    }

    //盛世美颜
    private void SSMY() {
        System.out.println("运行盛世美颜!");
    }

    //延年益寿
    private void YNYS() {
        System.out.println("运行演练益寿!");
    }

    //功能菜单
    private void functionMenu() {
        System.out.println("显示功能菜单:");
        System.out.println("\t\t1.延年益寿");
        System.out.println("\t\t2.盛世美颜");
        System.out.println("\t\t3.强身健体");
        System.out.println("\t\t4.升官发财");
        System.out.println("\t\t5.找到爱情");
        System.out.println("\t\t8.其他愿望");

    }

    //诅咒
    private void ZZ() {
        System.out.println("运行诅咒功能!");
    }

    //祈祷
    private void QD() {
        System.out.println("运行祈祷功能!");
    }

    //中文菜单
    private void CN() {
        System.out.println("\t\t1.祈祷");
        System.out.println("\t\t2.诅咒");
        System.out.println("\t\t3.实现愿望");
        System.out.println("\t\t4.还愿");
        System.out.println("\t\t5.高考分数查询");
        System.out.println("\t\t0.退出系统");
        userChoice();
    }

    //用户选择语言
    private int showCNU() {
        System.out.println("请选择您的语言:");
        System.out.println("\t\t1.中文");
        System.out.println("\t\t2.English");
        return input.nextInt();
    }

    //欢迎语句
    public void wlecome(){
        System.out.println("欢迎来到神灯客服!");
    }
}

扩展英文平台

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Scanner;

public class GameUS {
    //扫描仪
    Scanner input = new Scanner(System.in);

    //用户输入的愿望
    String yw;

    public void game(){
        //显示欢迎语句
        wlecome();

        //循环显示主菜单
        runMian();
    }

    private void runMian() {
        //显示中文菜单
        int lan = showCNU();

        //循环
        menuLoop(lan);
    }

    private void menuLoop(int lan) {
        while (true){
            switch (lan){
                case 1:
                    CN();
                    break;
                case 2:
                    US();
                    break;
            }

        }

    }

    //英文菜单
    private void US() {
        System.out.println("\t\t1.pray");
        System.out.println("\t\t2.Damnation");
        System.out.println("\t\t3.Realize one's wish");
        System.out.println("\t\t4.Fulfill one's wish");
        System.out.println("\t\t5.College entrance examination score query");
        System.out.println("\t\t0.Exit the system");
        userChoice();
    }

    //用户选择
    private void userChoice() {
        System.out.println("Please select the service you want:");
        int userchoice = input.nextInt();
        switch(userchoice){
            case 1:
                //祈祷
                QD();
                break;
            case 2:
                //诅咒
                ZZ();
                break;
            case 3:
                //实现愿望
                SXYW();
                break;
            case 4:
                //还愿
                HY();
                break;
            case 5:
                //高考分数查询
                GGFSCX();
                break;

            default:
                //如果用户非法输入, 返回主菜单
                System.out.println("Illegal input! Return to the main menu!");
                break;
        }
    }

    //高考分数查询
    private void GGFSCX() {
        System.out.println("Run the college entrance examination score query!");
    }

    //还愿
    private void HY() {
        System.out.println("Run still wish!");
    }

    //实现愿望
    private void SXYW() {
        //显示功能菜单
        functionMenu();
        //用户输入功能
        userInput();
    }

    //用户输入功能
    private void userInput() {
        //用户输入需要的功能
        System.out.print("Please select the function you need:");
        int userChiose = input.nextInt();
        //分支
        switch(userChiose){
            case 1:
                //延年益寿
                YNYS();
                break;
            case 2:
                //盛世美颜
                SSMY();
                break;
            case 3:
                //强生健体
                QSJT();
                break;
            case 4:
                //升官发财
                SGFC();
                break;
            case 5:
                //找到爱情
                ZDAQ();
                break;
            case 8:
                //其他愿望
                QTYW();
                break;
            default:
                //如果用户非法输入, 返回主菜单
                System.out.println("Illegal input!");
                System.out.println("Return to the main menu!");
                break;
        }
    }

    //其他愿望
    private void QTYW() {
        System.out.println("Run other wishes!");
        //接入客服
        customerService();
        //客服接入
        userInputDesire();
    }

    //客服接入
    private void userInputDesire() {
        //用户输入愿望
        System.out.println("Customer service connected");
        System.out.println("Please enter your wishes:");
        yw = input.next();

        //询问用户是否加一元换购零食
        System.out.println("Do you want to add one yuan for a bag of instant noodles(y/n)?");
        String hg = input.next();

        //询问用用户是否要新出来的瓜子
        System.out.println("\n" +
                "Master, we have withdrawn from the latest taste of spicy melon seeds. Do you need them(y/n)?");
        String gz = input.next();

        //询问用户是否要再许一个愿望换积分
        System.out.println("Your wish“"+yw+"“can have 6 points, and one point is still missing to exchange for a new" +
                " wish. Do you want to choose another one to collect enough points(y/n)?");
        String userInputYW = input.next();
        //判断用户是否在要一个愿望
        if (userInputYW.equals("y")){
            System.out.println("Please enter your next wish:");
            String yw02 = input.next();
        }

        //请问是否要办一张会员卡
        System.out.println("Would you like to apply for a membership card(y/n/b):");
        System.out.println("\t\ty.To be a member");
        System.out.println("\t\tn.Don't be a member");
        System.out.println("\t\tb.Beat him up");
        String vip = input.next();

        //分支
        switch(vip){
            case "y":
                System.out.println("I want to get a membership card!");
                break;
            case "n":
                //询问是否是VIP
                noVip();
                break;
            case "b":
                System.out.println("Beat up the magic lamp!");
                System.exit(0);
                break;
        }
    }

    //询问是否是VIP
    private void noVip() {
        //用户输入
        System.out.println("Is it a VIP(y/n):");
        String vip = input.next();

        //判断
        if (vip.equals("y")){
            System.out.println("Alas, not a VIP to open an advertisement!");
            System.out.println("job-hunting...");
        }
        time();
    }

    //上班时间
    private void time() {
        System.out.println("Hello, the working hours of customer service are: 9:00 - 16:00");
        //调用时间对象
        Date date = new Date();
        //设置输出格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
        //录入时间
        String daytime = simpleDateFormat.format(new Date());
        //打印时间
        System.out.println("present time:"+daytime);

        //判断是否是工作时间

        //获取小时
        int workTime = date.getHours();
        //判断工作时间
        if (workTime >=9 && workTime<=16){
            System.out.println("It's work time!");
            System.out.println("Show wishes!");
            return;
        }else{
            System.out.println("It's off duty now!");
            System.out.println("Please pay attention to customer service hours!");
            System.exit(0);
        }
    }

    //接入客服
    private void customerService() {
        System.out.println("Transferring to manual seat...");
        while(true){
            //输出音乐
            System.out.println("La La La...");

            //随机数
            Random random = new Random();

            //取随机数 0 - 3
            int randomNum = random.nextInt(3);

            //判断随机数是否为0,
            if (randomNum==0){
                //是的就接入客服
                System.out.println("Waiting for success, connecting to customer service!");
                break;
            }else{
                //不是就询问用户是否等待

                //询问用户是否继续等待
                System.out.println("All seats are busy. Do you want to continue waiting:");
                System.out.println("\t\t1.Keep waiting");
                System.out.println("\t\t2.User selected hang up");
                int userInput = input.nextInt();

                //判断
                if (userInput == 1){
                    //用户选择 1 继续循环
                    System.out.println("The user has chosen to continue waiting!");
                }else if (userInput == 2){
                    //用户选择 2 退出系统
                    System.out.println("User selected hang up!");
                    System.exit(0);
                }
            }

        }
    }

    //找到爱情
    private void ZDAQ() {
        System.out.println("Run to find love!");
    }

    //升官发财
    private void SGFC() { System.out.println("Run promotion and get rich!"); }

    //强身健体
    private void QSJT() {
        System.out.println("Run Johnson & Johnson fitness!");
    }

    //盛世美颜
    private void SSMY() {
        System.out.println("Run Shengshi beauty!");
    }

    //延年益寿
    private void YNYS() {
        System.out.println("Running drill for longevity!");
    }

    //功能菜单
    private void functionMenu() {
        System.out.println("Display function menu:");
        System.out.println("\t\t1.prolong life");
        System.out.println("\t\t2.Flourishing beauty");
        System.out.println("\t\t3.build up a good physique and improve one's health");
        System.out.println("\t\t4.win promotion and get rich");
        System.out.println("\t\t5.Find love");
        System.out.println("\t\t8.Other wishes");

    }

    //诅咒
    private void ZZ() {
        System.out.println("Run curse function!");
    }

    //祈祷
    private void QD() {
        System.out.println("Run prayer function!");
    }

    //中文菜单
    private void CN() {
        System.out.println("\t\t1.pray");
        System.out.println("\t\t2.Damnation");
        System.out.println("\t\t3.Realize one's wish");
        System.out.println("\t\t4.Fulfill one's wish");
        System.out.println("\t\t5.College entrance examination score query");
        System.out.println("\t\t0.Exit the system");
        userChoice();
    }

    //用户选择语言
    private int showCNU() {
        System.out.println("Please select your language:");
        System.out.println("\t\t1.Chinese");
        System.out.println("\t\t2.English");
        return input.nextInt();
    }

    //欢迎语句
    public void wlecome(){
        System.out.println("Welcome to magic lamp customer service!");
    }
}

运行程序

public class Test {
    public static void main(String[] args) {
        //实例化对象
        GameCN game = new GameCN();
        //让系统运行起来
        game.game();
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SSOA6

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值