嘿所以我这里有一个代码,旨在为每周和每日价格作为常数提供最优惠的汽车租赁价格。代码将采用颜色,租赁类型和天数,但不输出任何内容。我错过了什么吗?
import java.util.*;
import java.util.Scanner;
public class lab3
{
public static final char E = 'E';
public static final int ZERO = 0;
public static final double ECONOMY_DAILY = 25.5;
public static final double FULL_DAILY = 39.4;
public static final double ECONOMY_WEEKLY = 120.5;
public static final double FULL_WEEKLY = 216.25;
public static void main (String[] args)
{
Scanner Keyboard = new Scanner(System.in);
Locale locale = Locale.getDefault();
System.out.println("Enter the color of the vehicle:");
String color = Keyboard.next();
System.out.println ("Economy or Full:");
String Type = Keyboard.next();
char FirstTypeLetter = Type.toUpperCase()
.charAt(0);
System.out.println("For how many days?");
int Days = Keyboard.nextInt();
int Weeks = Days/7;
int DaysLeftover = Days%7;
switch (FirstTypeLetter)
{
case 'E':
double Rate1 = Weeks * ECONOMY_WEEKLY;
double Rate2 = (Weeks * ECONOMY_WEEKLY) + (Days * ECONOMY_DAILY);
double Rate3 = (Days * ECONOMY_DAILY);
if ((Rate1 > Rate2)&(Rate1>Rate3))
{
System.out.println("This is the best rate for a" + " " + color + " " + Type + " vehicle for" + " " + Days + "days:" + Rate1);
if ((Rate2>Rate1)&(Rate2>Rate3))
{
System.out.println("This is the best rate for a" + " " + color + " " + Type + " vehicle for" + " " + Days + "days:" + Rate2);
}
else if ((Rate3>Rate2) & (Rate3>Rate1))
{
System.out.println("This is the best rate for a" + " " + color + " " + Type + " vehicle for" + " " + Days + "days:" + Rate3);
switch (FirstTypeLetter)
{
case 'F':
double FullRate1 = Weeks * FULL_WEEKLY;
double FullRate2 = (Weeks * FULL_WEEKLY) + (Days * FULL_DAILY);
double FullRate3 = (Days * ECONOMY_DAILY);
if ((Rate1 > Rate2) & (Rate1 > Rate3))
{
System.out.println("This is the best rate for a" + " " + color + " " + Type + " vehicle for" + " " + Days + "days:" + FullRate1);
}
if ((FullRate2 > FullRate1) & (FullRate2 > FullRate3))
{
System.out.println("This is the best rate for a" + " " + color + " " + Type + " vehicle for" + " " + Days + "days:" + FullRate2);
}
else if ((FullRate3 > FullRate1) & (FullRate3 > FullRate2))
{
System.out.println("This is the best rate for a" + " " + color + " " + Type + " vehicle for" + " " + Days + "days:" + FullRate3);
}
break;
default:
System.out.println("Try Again!");
}
}
答案 0 :(得分:0)
您的代码没有意义。
在您的case 'E'
中,您有另一个使用相同变量的开关参数,然后检查case 'F'
使用if
语句时,您使用&
代替&&
由于您只有两个案例E
和F
,我建议您使用简单的if
声明
if (FirstTypeLetter == 'E' && Rate1 > Rate2 && Rate1>Rate3)
{
}
答案 1 :(得分:0)
问题是您错误地格式化了switch语句。 它应该是这样的:
// typedef can be used anywhere in the decl-specifier-seq
long unsigned typedef int long ullong;