The question ask:
Write a program that asks the user to enter one of the following state abbreviations: NC, SC, GA, FL, or AL. The program should then display the name of the state that corresponds with the abbreviation entered (North Carolina, South Carolina, Georgia, Florida, or Alabama).
This is what I have:
import java.util.Scanner;
class States
{
public static void main(String [] args)
{
//variable declarations
int state = 0; //stores user input
//establish a Scanner for input
Scanner userInput = new Scanner(System.in);
//prompt user to enter one of the following state
//abbreviation: AL, FL, GA, NC, SC
System.out.println("Please enter one of the following state abbreviation: AL, FL, GA, NC, or SC.");
//get value from user and store in variable
state = userInput.nextInt();
//validate user input, making sure the state abbreviation is
//either AL, FL, GA, NC, or SC
while(state = AL, FL, GA, NC, SC)
{
System.out.println("You entered an invalid abbreviation");
//prompt user to enter a valid state abbreviation
System.out.println("Please enter one of the following state abbreviation: AL, FL, GA, NC, or SC.");
//get value from user and store in variable
state = userInput.nextInt();
}
//user an if/else statement to display the correct state abbreviation
if(state = AL)
{
System.out.println(state + " = Alabama");
}
else if(state == FL)
{
System.out.println(state + " = Florida");
}
else if(state == GA)
{
System.out.println(state + " = Georgia");
}
else if(state == NC)
{
System.out.println(state + " = North Carolina");
}
else if(state == SC)
{
System.out.println(state + " = South Carolina");
}
}
}
It says I have 4 errors. What is it that I'm doing wrong? Thanks!