Michael.Chute
Baseband Member
- Messages
- 26
- Location
- United States
I need to allow the following programing steps to allow two decimal places not only at the end of every result but also allowed in the input portion up to two decimals. Example $1.99 + $1.99 = $3.98 as compared to using this and getting an error in return because I can't input decimals nor do I get a result of a decimal.
Note: The following line are supposed to be used according to the teacher but since I couldn't figure out how to get it to give me the outcome I needed I coded with it and worked around it by reconfiguring the mathematics and redoing the problem in a following problem. So please disregard.
Code:
package storeapplication;
import java.util.Scanner;
public class StoreApplication {
public static void main(String[] args) {
System.out.printf( "%s\n%s\n%s\n\n",
"----------Welcome to Michael's Natural Spring Water----------", "We buy natural spring water directly from Maine and stright \ninto the hands of the customer.", "PROMOTION: 10% off your purchase of more than 100 pounds of \nMichael's Natural Spring Water");
Scanner input = new Scanner( System.in );
int PriceBeforeTaxes;
int QuantityOfItem;
int ItemWeight;
int PricePerPound;
int TotalPriceWithTaxesFraud;
int TaxRate;
int TotalPriceWithTaxesActual;
System.out.printf("Quantity of item? X ");
QuantityOfItem = input.nextInt();
System.out.printf("Weight of item in pounds? LBS ");
ItemWeight = input.nextInt();
System.out.printf("Price per pound of item? $/LBS ");
PricePerPound = input.nextInt();
if( ItemWeight <= 100){
PriceBeforeTaxes = QuantityOfItem*ItemWeight*PricePerPound;
System.out.printf("Your total before taxes comes out to... = $%d.00\n\n", PriceBeforeTaxes);
System.out.printf("What is your local tax rate? %%");
TaxRate = input.nextInt();
TotalPriceWithTaxesFraud = PriceBeforeTaxes*(1+TaxRate);
TotalPriceWithTaxesActual = ((TotalPriceWithTaxesFraud-1)/100)+PriceBeforeTaxes;
System.out.printf("\nYout total with taxes comes out to... SUB TOTAL = $%d\n\n", TotalPriceWithTaxesActual);}
if( ItemWeight >= 101){
PriceBeforeTaxes = (QuantityOfItem*ItemWeight*PricePerPound)-((QuantityOfItem*ItemWeight*PricePerPound)/10);
System.out.printf("Your total with a 10%% discount before taxes comes out to... = $%d.00\n\n", PriceBeforeTaxes);
System.out.printf("What is your local tax rate? %%");
TaxRate = input.nextInt();
TotalPriceWithTaxesFraud = PriceBeforeTaxes*(1+TaxRate);
TotalPriceWithTaxesActual = (((TotalPriceWithTaxesFraud-1)/100)-((TotalPriceWithTaxesFraud-1)/100)/10)+PriceBeforeTaxes;
System.out.printf("\nYout total with a 10%% discount taxes comes out to with a 10%% discount... SUB TOTAL = $%d\n\n", TotalPriceWithTaxesActual);}
}
}
Note: The following line are supposed to be used according to the teacher but since I couldn't figure out how to get it to give me the outcome I needed I coded with it and worked around it by reconfiguring the mathematics and redoing the problem in a following problem. So please disregard.
TotalPriceWithTaxesFraud = PriceBeforeTaxes*(1+TaxRate);