I'm a Java beginner and this is for my software class. The general project is pretty simple, it asks you to tell the user what their sales tax is and what their new total is based on that, based on which US state they're in. I'm trying to make it so when they input (through the Scanner), for example, "Wisconsin" after the "which state are you in" prompt, I get the value of ".05" to use since that's Wisconsin's state tax.
I have made both arrays, I just don't know how to access a value from an array using values from another. Everything is in the correct corresponding order, as in Alabama's tax rate is 4% (.04), Alaska's is 0%, and so on.
import java.util.Scanner;
public class SalesTax {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double sale;
double salesTax;
double total;
double[] taxRate = { .04, 0, .56, .65, .75,
.29, .0635, 0, .06, .04,
.04, .06, .0625, .07, .06,
.065, .06, .04, .055, .06,
.0625, .06, .06875, .07, .04225, 0,
.055, .0685, 0, .07, .05125,
.04, .0475, .05, .0575, .045,
0, .06, .07, .06, .04,
.07, .0625, .0595, .06, .0530,
.065, .06, .05, .04, .0575 };
String[] states = { "Alabama", "Alaska", "Arizona", "Arkansas", "California",
"Colorado", "Connecticut", "Delaware", "Florida", "Georgia",
"Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland",
"Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri",
"Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey",
"New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina",
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
"Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming" };
System.out.println("Enter the state you are in (please type the full name): ");
states = input.nextLine();
System.out.println("Enter the amount of the sale: ");
sale = input.nextDouble();
}
}
I'm really just not sure where to go from here. Once I'm able to reference the value I should be able to code the rest of it easily. If more information is needed, let me know.