Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class TaxCalculator {
- public static double calculateSalesTax(String state, double price) {
- double due = 0.0;
- if (state.equalsIgnoreCase("virginia")) {
- due = price * 0.05;
- }
- else if (state.equalsIgnoreCase("maryland")) {
- due = price * 0.04;
- }
- else if (state.equalsIgnoreCase("dc")) {
- due = price * 0.03;
- }
- return due;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter the name of the state: ");
- String state = scanner.nextLine();
- System.out.println("Enter price: ");
- double price = scanner.nextDouble();
- double due = calculateSalesTax(state,price);
- if (due == 0.0) System.out.println("You provided an invalid State.");
- else System.out.println("The tax due on an item costing $" + price + " in the state of " + state + " is $" + due);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement