【发布时间】:2018-10-25 22:48:43
【问题描述】:
所以我非常困惑,只是在寻求帮助:L。这是我导师的指示。
说明: 使用哨兵值循环。
询问每个用户:
- 车辆类型(可能使用字符串以外的其他内容,例如:1 经济型,轿车 2 等)
- 租用天数
计算(针对每个客户):
- 租金,
- 税收,
- 到期总额。
共有三种不同的租金选择:经济型 @ 31.76、轿车 @ 40.32、SUV @ 47.56。 [注意:只考虑全天单位(无小时费率)]。
销售税为 TOTAL 的 6%。
使用以下方法创建摘要数据:
- 客户数量
- 收款总额。
另外,包括 IPO、算法和案头检查值(设计文档)。
{我要做什么和我的问题}
package yipe;
public class Umm {
import java.util.*;
int count = 0;
static int CarType, days;
static double DailyFee, Total;
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("What vehical would you like to rent?\n");
System.out.println("Enter 1 for an economy car\n");
System.out.println("Enter 2 for a sedan car\n");
System.out.println("Enter 3 for an SUV");
CarType = keyboard.nextInt();
if (CarType == '1')
DailyFee=(int)31.76;
else if(CarType == '2')
DailyFee=(int)40.32;
else if(CarType == '3')
DailyFee=(int)43.50;
System.out.print("Please enter the number of days rented. (Example; 3) : ");
days = keyboard.nextInt();
Total = (DailyFee * days * 6/100);
System.out.printf("The total amount due is $" + Total);
}
}
- 如何修正我的 IF 语句以获得正确的数学结果?
- 如何让它循环输入多个信息??
- 如何制作汇总数据?
- 如何将总数四舍五入到小数点后两位?
【问题讨论】:
-
== 1, == 2. 不是 == '1'。
-
CarType 是一个 int,您正在尝试将其与 chars '1' 等进行比较...删除 's
-
非常感谢我非常感谢您的帮助,我这样做了,但仍然,我的数学公式在尝试计算租用天数 (*) 加号 (+) 时似乎仍然关闭那 6%。
-
请不要在问题得到回答后对其进行编辑,以便将来有类似问题的读者理解。
-
@EJoshuaS 但尚未完全回答。是否试图澄清接下来的两个问题?
标签: java loops if-statement summary sentinel