Advertisement
a1ananth

test

Oct 24th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class TaxCalculator {
  4.     public static double calculateSalesTax(String state, double price) {
  5.         double due = 0.0;
  6.        
  7.         if (state.equalsIgnoreCase("virginia")) {
  8.             due = price * 0.05;
  9.         }
  10.         else if (state.equalsIgnoreCase("maryland")) {
  11.             due = price * 0.04;
  12.         }
  13.         else if (state.equalsIgnoreCase("dc")) {
  14.             due = price * 0.03;
  15.         }
  16.        
  17.         return due;
  18.     }
  19.    
  20.     public static void main(String[] args) {
  21.         Scanner scanner = new Scanner(System.in);
  22.        
  23.         System.out.println("Enter the name of the state: ");
  24.         String state = scanner.nextLine();
  25.        
  26.         System.out.println("Enter price: ");
  27.         double price = scanner.nextDouble();
  28.        
  29.         double due = calculateSalesTax(state,price);
  30.        
  31.         if (due == 0.0) System.out.println("You provided an invalid State.");
  32.         else System.out.println("The tax due on an item costing $" + price + " in the state of " + state + " is $" + due);
  33.     }
  34.    
  35.    
  36. }
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement