Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

asks the user to enter the name of the state asks the user to enter the price of

ID: 3631413 • Letter: A

Question


asks the user to enter the name of the state
asks the user to enter the price of the item purchased
calls the calculateSalesTax method, passing to it the name of the state and the price of the item purchased
accepts the returned value, and assign it to a variable
says "The tax due on an item costing $ [put the price] in the state of [put name of state] is $ [put the amount of tax due]

Write a method called calculateSalesTax
two parameters: String state, double price
if the state is Virginia, the tax rate is 5% (price * .05)
if the state is Maryland, the tax rate is 4% (price * .04)
if the state is DC, the tax rate is 3% (price * .03)
the method returns a double, which is the taxDue

Explanation / Answer

Sorry the indentation isn't proper here... Check http://pastebin.com/ab4aZveA for proper syntax highlighting and indentation.

Please rate :)

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); } }