Return to Snippet

Revision: 61151
at November 30, 2012 12:07 by brandonfreeman


Initial Code
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

Initial URL


Initial Description
Question 1 for CS1030 Group 2 Assignment 7

Initial Title
Question 1: Grocery Tax Calculator

Initial Tags


Initial Language
Java