gpt4 book ai didi

java - 问 : Rental Car Calculator | Use a sentinel value loop

转载 作者:行者123 更新时间:2023-12-02 10:39:33 25 4
gpt4 key购买 nike

我很困惑我是否正确遵循了这一点,并且正在寻求安慰和一些帮助。所以我的主要问题是我是否遵循我的讲师问题:当他说使用哨兵值循环构建它时?

其次,如何将总计四舍五入到小数点后两位?

如果这对我的作业有帮助的话是这样的:

说明:使用哨兵值循环。

询问每个用户:

车辆类型(可以使用字符串以外的其他内容,例如:1 表示经济型,2 表示轿车等)租用天数计算(对于每个客户):

租金成本,税收,总应付款。共有三种不同的租赁选项,价格各异:经济型 @ 31.76、轿车 @ 40.32、SUV @ 47.56。 [注意:仅考虑全天单位(无小时费率)]。

销售税 = 总额的 6%。

创建摘要数据:

客户数量收集的总金额。此外,还包括 IPO、算法和案头检查值(设计文档)。

{我的设计和进展}

包yipe;

导入java.util.*;导入java.lang.Math;

公开课嗯{

int count = 0;
static int days;
static double DailyFee, NontaxTotal, CarType, 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=31.76;
else if(CarType == 2)
DailyFee=40.32;
else if(CarType == 3)
DailyFee=43.50;

System.out.print("Please enter the number of days rented. (Example; 3) : ");
days = keyboard.nextInt();

NontaxTotal = (DailyFee * days);
Total = (NontaxTotal * 1.06);







System.out.printf("The total amount due is $" + Total);

}

}

最佳答案

布兰登,没有哨兵循环。在我看来,这就是您想要的程序,

import java.util.*;

public class Stack3{
public static void main(String []args){
int count=0;
int days;
double DailyFee=0, NontaxTotal, CarType, Total,FullTotal=0;
Scanner in=new Scanner(System.in);
System.out.println("If there are any customer press 1 else press 0");
int cus=in.nextInt();
// this is sentinel loop
while(cus!=0){
count++;
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 = in.nextInt();
if (CarType == 1)
DailyFee=31.76;
else if(CarType == 2)
DailyFee=40.32;
else if(CarType == 3)
DailyFee=43.50;

System.out.print("Please enter the number of days rented. (Example; 3) : ");
days = in.nextInt();
double x=days;
NontaxTotal = (DailyFee * x);
Total = (NontaxTotal * 1.06);
FullTotal+=Total;
//included 2 decimals only
System.out.printf("The total amount due is $ %.2f \n",Total);

System.out.println("If there are any customer press 1 else press 0");
cus=in.nextInt();
}
System.out.println("Count of customers :- "+count);
System.out.printf("Total of the Day :- %.2f",FullTotal);
}
}

关于java - 问 : Rental Car Calculator | Use a sentinel value loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53024921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com