Java Q:租车计算器|使用哨兵值循环
我很困惑,如果我遵循这一权利,是一种寻求安慰和一些帮助。所以我的主要问题是我是否遵循我的指导老师的问题是:当他说使用sentinel值循环构建它时 第二,我怎样才能把总数四舍五入到只有两位小数 如果这对我的作业有帮助的话: 说明:使用sentinel值循环 向每个用户询问: 车辆类型(可能使用字符串以外的其他内容,例如:1表示经济型,2表示轿车等) 租用天数 计算(每个客户的)成本: 租金, 税, 应付总额。 有三种不同的租金选择,价格不同:经济型31.76英镑,轿车40.32英镑,SUV 47.56英镑。[注:仅考虑全天单位(无小时费率)] 销售税=总额的6% 使用以下内容创建摘要数据: 顾客人数 收集的总金额。 此外,还包括IPO、算法和桌面检查值(设计文档) {我的设计与进度} 包装业 导入java.util.*; 导入java.lang.Math 公共课{Java Q:租车计算器|使用哨兵值循环,java,if-statement,static,double,summary,Java,If Statement,Static,Double,Summary,我很困惑,如果我遵循这一权利,是一种寻求安慰和一些帮助。所以我的主要问题是我是否遵循我的指导老师的问题是:当他说使用sentinel值循环构建它时 第二,我怎样才能把总数四舍五入到只有两位小数 如果这对我的作业有帮助的话: 说明:使用sentinel值循环 向每个用户询问: 车辆类型(可能使用字符串以外的其他内容,例如:1表示经济型,2表示轿车等) 租用天数 计算(每个客户的)成本: 租金, 税, 应付总额。 有三种不同的租金选择,价格不同:经济型31.76英镑,轿车40.32英镑,SUV 47
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);
}
}
似乎您的讲师希望您创建一个循环,并让多个客户租车“使用sentinel值循环”我在您的代码中没有看到任何循环。@Andreas我如何看待创建循环,我感到非常失落,我很抱歉:(.自从我问这个问题以来,我一直在玩eclipse java,我想出了一些类似的东西,但没有那么干净。非常感谢!参考这个你回答了很多问题。另外,我希望我能喜欢这个或任何东西来回报我的感激之情。谢谢,非常!:)无论如何,我很高兴听到这个消息。