D'accord, j'essaye d'obtenir que l'utilisateur saisisse le mot "random" ou un nombre (0.01) pour une taxe de vente et mon invite peut seulement utiliser keybd.next() ou keybd.nextDouble() alors comment ferais-je facilement cela?Java comment utiliser un double ou une chaîne?
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);
}
Merci
Ceci est utile, mais je ne sais pas comment l'utiliser lol. Oui, j'utilise un scanner – tekman22
Je ne sais pas comment utiliser ... quoi? –
Comment l'utiliser? – tekman22