好吧,我想让用户输入“随机”一词或一个数字(0.01)的销售税,我的提示只能使用keybd.next()或keybd.nextDouble(),所以如何我会轻易做到这一点吗?Java如何使用double或string?
public void calculateSalesReceipt(){
System.out.println("Enter the sales tax percentage (ex. 0.08 for 8%) or type \"random\" for a random number: ");
double tax = keybd.nextDouble();
if(tax < 0){
System.out.println("You must enter a value equal to or greater than 0!");
}else{
getFinalPricePreTax();
total = total;
taxcost = total * tax;
double finaltotal = total * taxcost;
System.out.println("Sales Receipt");
System.out.println("-------------");
for(Item currentProduct : shoppingBag){
System.out.println(currentProduct.getName() + " - " + currentProduct.getUnits() + " units " + " - $" + currentProduct.getCost());
}
System.out.println("Total cost: $" + total);
System.out.println("Total tax: $" + taxcost);
System.out.println("Total cost with tax: $" + finaltotal);
}
感谢
这是有帮助的,但我不知道如何使用它大声笑。是的,我正在使用扫描仪 – tekman22 2011-05-07 19:11:18
不知道如何使用...什么? – 2011-05-07 19:25:27
我会如何使用它? – tekman22 2011-05-07 19:33:18