I am writing a code for my Java class that calls for me to create something that looks like a bill/receipt. similar to:
Item quantity price total
gum 10 $1.49 $14.90
soda 3 $1.00 $3.00
chips 20 $1.25 $20.00
I am using the printf(); method. The variables i have declared are
double gumPrice = 1.49;
float gumQuantity = 10;
double gumTotal = 14.90;
double sodaPrice = 1.00;
float sodaQuantity = 3;
double sodaTotal = 3.00;
double chipsPrice = 1.25;
float chipsQuantity = 20;
double chipsTotal = 25.00;
i need to create a few printf(); statements to list the data in that manner.
This is what i have so far for gum, which is giving me an error.
System.out.printf("%-30s %-10.2f %-10.2f %-5.2f", "Gum",gumQuantity,"$"+gumPrice,"$"+gumTotal);
What is the correct way to put a double in a printf(); while listing multiple arguments in one line?
%fparameters.%-10.2f,%-5.2fto%-10.2s,%-5.2ssince"$"+gumPrice,"$"+gumTotalis a string not doubleString.format("$%.2f", gumPrice)and similarly forgumTotalto make it look right.