首页 > 解决方案 > 如何解决“buyTickets”类

问题描述

需要帮助解决项目的课程。不能引入新变量。有 U、L 和 F 票类型(上、下、楼层) 多张票的测试程序测试。这些值:

private static final double PRICE_UPPER_TICKET = 29.9;
private static final double PRICE_LOWER_TICKET = 99.0;
private static final double PRICE_FLOOR_TICKET = 180.0;
private static int TOTAL_NUMBER_FLOOR_TICKETS= 400;
private static int TOTAL_NUMBER_LOWER_TICKETS= 300;
private static int TOTAL_NUMBER_UPPER_TICKETS= 300;

public void buyTickets (char ticketType, int numTickets, double pmt)

尝试了许多 if 语句。下面是我的代码。

if  ('L' < numTickets){
            if(pmt < PRICE_LOWER_TICKET * numTickets){
                System.out.println("Insuffient funds");
            }
            pmt = PRICE_LOWER_TICKET * numTickets;
            totalSales = pmt + totalSales;
            System.out.println(pmt);
        }
       }

只是吐出0。

标签: java

解决方案


You need to check the ticket type char first off to know which price and which total tickets variable to use (eg ticketType == 'L' will mean use lower tickets price and total) then check their payment is greater than the ticketprice * numTickets for that ticket area AND check the number of tickets < the total tickets available for that area. Hope this helps


推荐阅读