我想用字母来代替数字。所以这将是R免费停车,C为有盖停车场,G为车库停车场。我试图将其转换为if语句,但似乎无法弄清楚如何让它的工作任何帮助,将不胜感激。如何在java中使用开关大小写字符?
/*get users parking choice*/
System.out.println("What kind of parking would you like press 1 for free parking, " +
" 2 for a Covered parking, or 3 for garage parking");
parking = garageType.nextInt();
switch (parking){
case 1:
type = "free";
gPrice = 0;
break;
case 2:
type = "covered";
gPrice = 3000;
break;
case 3:
type = "garage";
gPrice = 6000;
break;
default:
System.out.println("That was an invalid option please try again");
break;
}
/* get total price*/
total = condoPrice+gPrice;
/*show the user their choices and condo, parking and total price*/
System.out.println("You have selected a condo with a view of the "
+ view + " for $" + condoPrice + " with " + type + " parking, " +
" your total for this condo and parking is $ " + total);
}
只要'garageType.nextChar()',然后将案例更改为''R'等。 – Jameson
谢谢你的帮助。 –