如果我遵循这项权利,我会感到困惑,并且在寻求一些帮助的同时也感到放心。所以我的主要问题是我是否跟随我的讲师的问题是:当他说使用哨兵值循环进行构建时?
第二,如何将“总计”仅舍入到两位小数?
如果对我的任务有帮助的话:
说明:使用前哨值循环。
向每个用户询问:
车辆类型(可以使用字符串以外的其他方式,例如:1用于经济性,2用于轿车等) 出租天数 计算(针对每个客户):
租金, 税金 应付总额。 共有三种不同的租金选项,分别收取不同的费用:经济型@ 31.76,轿车@ 40.32,SUV @ 47.56。 [注意:仅考虑全天单位(无小时费率)。
销售税为TOTAL的6%。
使用以下方法创建摘要数据:
客户数量 收款总额。 另外,包括IPO,算法和案头检查值(设计文件)。
{我的设计与进步}
包裹是;
导入java.util。*; 导入java.lang.Math;
公共课Umm {
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);
}
}
答案 0 :(得分:1)
布兰登,没有哨兵循环。在我看来,这是您想要的程序,
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);
}
}