public class Calculation
{
private double priceDouble, subTotalDouble, taxDouble,
shippingDouble, totalDouble;
private int quantityInteger;
private static double grandTotalDouble;
private static int totalNumberOfOrdersInteger;
public Calculation()
{
}
public Calculation(int quantityNewInteger, double priceNewDouble)
{
setQuantity(quantityNewInteger);
setPrice(priceNewDouble);
calculate();
}
private void setQuantity(int quantityNewInteger)
{
//assign public variable to private
quantityInteger = quantityNewInteger;
}
private void setPrice(double priceNewDouble)
{
//assign public variable to private
priceDouble = priceNewDouble;
}
private void calculate()
{
final int SHIPPING_RATE_INTEGER = 1;
final double TAX_RATE_DOUBLE = 0.0825;
//calculate the subTotal of the order
subTotalDouble = quantityInteger * priceDouble;
//calculate the shipping of the order
shippingDouble = SHIPPING_RATE_INTEGER * quantityInteger;
//calculate the Tax of the order
taxDouble = subTotalDouble * TAX_RATE_DOUBLE;
//calculate the Total including shipping and tax of the order
totalDouble = taxDouble + subTotalDouble + shippingDouble;
// calculate the total of all orders
//and the number of orders processed
grandTotalDouble += totalDouble;
totalNumberOfOrdersInteger++;
}
public double getQuantity()
{
//returning quantity
return quantityInteger;
}
public double getPrice()
{
//returning price
return priceDouble;
}
public double getSubTotal()
{
//returning subTotal
return subTotalDouble;
}
public double getShipping()
{
//returning shipping
return shippingDouble;
}
public double getTax()
{
//returning Tax
return taxDouble;
}
public double getTotal()
{
//returning grand total of orders
return totalDouble;
}
public double getGrandTotal()
{
//returning grand total of orders
return grandTotalDouble;
}
public int getNumberOfOrders()
{
//return total number of orders processed
return totalNumberOfOrdersInteger;
}
}