Friday, September 28, 2012

Java Exercise #6: Sales Tax

This exercise is to print a decimal calculation with 2 decimal places

Exercise: Print the sales tax for purchase amount of 197.55 @ 6% interest with 2 decimal places.

Sales tax for purchase amount of 197.55 @ 6% is 11.85

Download Code: Salex Tax

1 comment:

  1. Variations are possible. I personally used a slighty different code here:

    import java.text.DecimalFormat;

    public class Exercise6 {

    public static void main(String[] args){
    double total = 197.55;
    double tax;
    double interest = 0.06;
    double int_perc = interest*100;

    tax = total * interest;
    DecimalFormat df = new DecimalFormat("#.##");

    System.out.println("Sales tax for purchase amount of " +total+ " @ "+ int_perc+ "% is " +df.format(tax));
    }
    }

    Makes it slightly more automatizated. ;-)

    ReplyDelete