java - 如何解决“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)
- 现在,假设 numTickets 和 pmt 包含正 int 值
如果您要购买的特定部分/票类型中有可用的票数 (numTickets)。
根据票种和票数计算应付金额
- 如果作为输入参数输入的支付金额足以支付车票:1) 添加总销售额,2) 减少特定部分的可用车票数量,3) 显示交易结果。
- 如果作为输入参数输入的付款不足以支付门票:打印一条消息,指出金额有问题。客户无法购买门票。
尝试了许多 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。
解决方案
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
推荐阅读
- c++ - 如何使用 Polygon_mesh_slicer 的输出来控制 Surface_mesh_deformation CGAL 中的点?
- python - 为什么python要求您在等待条件之前获取锁
- python - 有没有一种方法可以将图像保存在 OpenCV 执行期间创建的子文件夹中
- wordpress - 将具有页面构建器内容的网站迁移到具有不同页面构建器的另一个主机的最有效方法
- r - 列表中数据帧的总和
- javascript - 在输入类型文本中,为什么我无法添加 - 在输入四个字母后使用 javascript?
- android - 如何禁用滚动recyclerview的自动更新?
- symfony - Symfony2,每次在第一次尝试网站上的空白页面,重新加载/刷新其工作后
- spring - 如何使用 Spring OAuth2 在启用了 Spring mvc 应用程序的 SSO 上单点注销?
- asp.net-mvc-5 - 如何在 asp.net mvc 5 中修复“模型代码生成器”