Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA:需要帮助修复我的电影票课程吗_Java - Fatal编程技术网

JAVA:需要帮助修复我的电影票课程吗

JAVA:需要帮助修复我的电影票课程吗,java,Java,我正在为一个课堂作业制作一个电影票程序,但在一些事情上遇到了一些困难 我不知道如何计算用户想要的门票的总成本,因为我不知道如何告诉程序使用不同的公式来计算日场票和夜场票 我还需要找到一种方法,不允许用户购买儿童票,如果电影评级为R 我的代码在下面 /** * @param args */ public static void main(String[] args) { //initializes variables for the various costs of each tic

我正在为一个课堂作业制作一个电影票程序,但在一些事情上遇到了一些困难

  • 我不知道如何计算用户想要的门票的总成本,因为我不知道如何告诉程序使用不同的公式来计算日场票和夜场票

  • 我还需要找到一种方法,不允许用户购买儿童票,如果电影评级为R

  • 我的代码在下面

    /**
     * @param args
     */
    public static void main(String[] args) 
    {
        //initializes variables for the various costs of each ticket
        double adultMatCost = 7.50;
        double adultEveCost = 9.50;
        double childMatCost = 7.00;
        double childEveCost = 7.00;
        double seniorMatCost = 5.00;
        double seniorEveCost = 7.00;
    
        //introduces the user to the program, creates scanner for program,
        //and asks user to enter their name
        Scanner scan = new Scanner(System.in);
        System.out.println("Welcome to the J-Town Theater.");
        System.out.print("Please enter a name for our transaction records:");
        String name = scan.next();
    
        //thanks user and asks user which movie they would like to choose
        //assigns a String movie is assigned text based on what the user chose
        //if user enters a value other than 1 or 2 the program terminates gracefully
        System.out.println("Thank you, " + name);
        System.out.println("Which movie would you like to see?");
        System.out.println("[1] My Little Pony (PG)");
        System.out.println("[2] Blade Runner 2049 (R)");
        System.out.print("Enter movie choice: ");
        int movieChoice = scan.nextInt();
        String movie = "";
            if (movieChoice == 1){
                movie = ("My Little Pony");
            }
            else if (movieChoice == 2){
                movie = ("Blade Runner 2049");
            }
            else{
                System.out.println("I'm sorry, " + name + ", but that is an invalid choice");
                System.out.println("Goodbye.");
                return;
            }
    
        //asks user what time they want to see the movie
        //user enters M/m for Matinee and E/e for evening
        //if user enters something besides M/m/E/e the program terminates gracefully
        System.out.println("What time of day would you like?");
        System.out.println("[M] Matinee");
        System.out.println("[E] Evening");
        System.out.print("Enter movie time:");
        String timeDay = scan.next();
        double totalCost = 0;
        String timeDayResult = "";
        double timeDayME = 0;
            if (timeDay.equals("m")){
                timeDayResult = ("Matinee showing");
            }
            else if (timeDay.equals("M")){
                timeDayResult = ("Matinee showing");
            }
            else if (timeDay.equals("e")){
                timeDayResult = ("Evening showing");
            }
            else if (timeDay.equals("E")){
                timeDayResult = ("Evening showing");
            }
            else{
                System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
                System.out.println("Goodbye.");
                return;
            }
    
        //asks how many tickets they would like and shows the price for each ticket
        //user enters number between 0 and 10 if they enter something besides that
        //the program will terminate gracefully
        //if the movie chosen was rated R no tickets can be sold to children
        System.out.println("How many tickets would you like?");
        System.out.println("Child : $7.00");
        System.out.println("Adult : $7.50");
        System.out.println("Senior: $5.00");
        System.out.print("Enter number of children (0-10):");
        int ticketsChild = scan.nextInt();
            if (ticketsChild >= 0){
                int ticketsChildTotal = ticketsChild;
            }
            if (ticketsChild <= 10){
                int ticketsChildTotal = ticketsChild;
            }
            else{
                System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
                System.out.println("Goodbye.");
                return;
            }
        System.out.print("Enter number of adults (0-10):");
        int ticketsAdult = scan.nextInt();
            if (ticketsAdult >= 0){
                int ticketsAdultTotal = ticketsAdult;
            }
            if (ticketsAdult <= 10){
                int ticketsAdultTotal = ticketsAdult;
            }
            else{
                System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
                System.out.println("Goodbye.");
                return;
            }
        System.out.print("Enter number of seniors (0-10):");
        int ticketsSenior = scan.nextInt();
            if (ticketsSenior >= 0){
                int ticketsSeniorTotal = ticketsSenior;
            }
            if (ticketsSenior <= 10){
                int ticketsSeniorTotal = ticketsSenior;
            }
            else{
                System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
                System.out.println("Goodbye.");
                return;
            }
    
        //gives a transaction summary for the user showing what movie they want,
        //what time they want, and how many tickets they want total,
        //then the program calculates the total ticket price
        System.out.println("Thank you, Penolope, here is a record of your purchase.");
        int totalTickets = ticketsSenior + ticketsAdult + ticketsChild;
        System.out.println(movie + " (" + timeDayResult + "): " + totalTickets + " tickets total");
        System.out.println("Children: " + ticketsChild);
        System.out.println("Adults: " + ticketsAdult);
        System.out.println("Seniors: " + ticketsSenior);
    
        double totalMatineeCost = (childMatCost * ticketsChild) + (adultMatCost * ticketsAdult) + (seniorMatCost + ticketsSenior);
        double totalEveningCost = (childMatCost * ticketsChild) + (adultMatCost * ticketsAdult) + (seniorMatCost + ticketsSenior);
    
    
        System.out.println("Total cost: $" + totalCost);
    
    }
    
    /**
    *@param args
    */
    公共静态void main(字符串[]args)
    {
    //为每张票的各种成本初始化变量
    双倍成人成本=7.50;
    双成人成本=9.50;
    双倍成本=7.00;
    双倍子女费用=7.00;
    双倍成本=5.00;
    双倍成本=7.00;
    //向用户介绍程序,为程序创建扫描仪,
    //并要求用户输入其名称
    扫描仪扫描=新扫描仪(System.in);
    System.out.println(“欢迎来到J城剧院”);
    System.out.print(“请为我们的交易记录输入名称:”);
    字符串名称=scan.next();
    //感谢用户并询问用户想要选择哪部电影
    //分配字符串根据用户选择的内容为电影分配文本
    //如果用户输入的值不是1或2,程序将正常终止
    System.out.println(“谢谢,”+name);
    System.out.println(“您想看哪部电影?”);
    System.out.println(“[1]我的小马(PG)”);
    系统输出打印项次(“[2]叶片转轮2049(R)”);
    System.out.print(“输入电影选项:”);
    int movieChoice=scan.nextInt();
    字符串电影=”;
    if(movieChoice==1){
    电影=(“我的小马”);
    }
    else if(movieChoice==2){
    电影=(“刀锋杀手2049”);
    }
    否则{
    System.out.println(“对不起,+name+”,但这是一个无效的选择);
    System.out.println(“再见”);
    返回;
    }
    //询问用户希望在何时观看电影
    //用户为日场输入M/M,为晚间输入E/E
    //如果用户输入M/M/E/E之外的内容,程序将优雅地终止
    System.out.println(“您希望在一天中的什么时候?”;
    System.out.println(“[M]日场”);
    System.out.println(“[E]晚上”);
    系统输出打印(“输入电影时间:”);
    字符串timeDay=scan.next();
    双重总成本=0;
    字符串timeDayResult=“”;
    双timeDayME=0;
    if(timeDay.equals(“m”)){
    timeDayResult=(“日场演出”);
    }
    else if(timeDay.equals(“M”)){
    timeDayResult=(“日场演出”);
    }
    else if(timeDay.equals(“e”)){
    timeDayResult=(“晚间演出”);
    }
    else if(timeDay.equals(“E”)){
    timeDayResult=(“晚间演出”);
    }
    否则{
    System.out.println(“对不起,+name+”,但这是一个无效的选择。”);
    System.out.println(“再见”);
    返回;
    }
    //询问他们想要多少张票,并显示每张票的价格
    //如果用户输入了除此之外的数字,则输入0到10之间的数字
    //程序将优雅地终止
    //如果选择的电影被评为R级,就不能向儿童出售任何电影票
    System.out.println(“您想要多少张票?”);
    System.out.println(“儿童:$7.00”);
    System.out.println(“成人:$7.50”);
    System.out.println(“高级:$5.00”);
    系统输出打印(“输入子项数(0-10):”;
    int ticketsChild=scan.nextInt();
    如果(ticketchild>=0){
    int ticketchildtotal=ticketchild;
    }
    如果(ticketchild=0){
    int ticketsadultottal=ticketsAdult;
    }
    如果(ticketsAdult=0){
    int ticketsSeniorTotal=ticketsSenior;
    }
    如果(票务高级)
    我不知道如何计算用户想要的门票的总成本,因为我不知道如何告诉程序使用不同的公式来计算日场票和夜场票

    您已经在两个单独的变量中计算了成本,因此只需使用一个条件,根据用户输入选择您需要的一个

    if("Matinee showing".equals(timeDayResult)){
        totalCost = totalMatineeCost;
    }else{
        totalCost = totalEveningCost;
    }
    
    我还需要找到一种方法,不允许用户购买儿童票,如果电影评级为R

    同样,在询问孩子的数量之前,使用一个条件。例如:

    if(movieChoice == 2){
        //Set number of child tickets to 0, perhaps inform user they are not allowed to buy child tickets since movie is rated R
    }else{
        //ask the user for number of child tickets
    }
    
    最后几点想法-您的程序中有几个bug。我注意到了这些,但可能还有更多:

    • 总成本的计算是错误的
    • 验证用户输入的逻辑错误

    请确保彻底测试代码。

    我已否决了此问题,因为没有证据表明对此代码执行了任何调试。请通过您的问题向我们说明调试发现了什么,以及有关实际代码行的特定问题。请参阅:和。