## Posted By

brandonfreeman on 11/30/12

# Question 1: Grocery Tax Calculator

/ Published in: Java

Question 1 for CS1030 Group 2 Assignment 7

`import java.util.*; public class taxCalculator{	public static void main (String[] args)	{ 		// initialization and setup		double foodBill =  150.00; // grocery bill total for food		double foodTaxRate =  0.03; // food sales tax 3%		double totalFoodTax =  0.00; // total food tax amount 		double nonFoodBill =  50.00; // grocery bill total for non-food		double nonFoodTaxRate = 0.0675; // non food tax 6.75%		double totalNonFoodTax =  0.00; // total non food tax amount 		double totalTaxes =  0.00;// total taxes for both food and nonfood bills		double rounded; // total tax rounded to the nearest cent  		// do calculations		totalFoodTax = foodBill * foodTaxRate;		totalNonFoodTax = nonFoodBill * nonFoodTaxRate;		totalTaxes = totalFoodTax + totalNonFoodTax;		rounded = Round(totalTaxes, 2); // pass in totalTaxes to be rounded 					        // and to which decimal place (2)					        // to the Round function 		//print results		System.out.println("The total tax for your bill is \$" + rounded);  	} // end main  	// round totalTaxes to the nearest cent	public static double Round(double Rval, int Rpl)	{		double p = Math.pow(10,Rpl);		Rval = Rval * p;		double tmp = Math.round(Rval);		return tmp/p; // return rounded value	} // end Round  } // end class`