Hi, I am fairly new to java and have been playing around with scanners and while trying to understand this problem I am running into an error
"Non-static variable vacation cannot be referenced from a static context"
Obviously this isn't quite a completed program, but I am not sure why vacation cannot be given a value within the if statement. When I try giving it a value outside of the if statement it works fine.
Any help with clarifying this would be greatly appreciated-thanks
import java.util.*;
public class MainClass
{
public static void main()
{
System.out.println("Enter the employee type (Professional or Hourly)");
Scanner scan = new Scanner(System.in);
String type = scan.nextLine();
type = type.toUpperCase();
System.out.println("Enter the employee's name");
String name = scan.nextLine();
System.out.println("Enter the employee's ID Number (int)");
int idNumber = scan.nextInt();
System.out.println("Enter the employee's pay (double)");
double pay = scan.nextDouble();
if (type.equals("PROFESSIONAL"))
{
System.out.println("Enter the employee's accrued vacation (int)");
int vacation = scan.nextInt();
}
else
{
Pay person1 = new Pay(name, idNumber, pay);
}
System.out.format("%s is id %d with pay $%.2f %d%n", name, idNumber, pay, vacation);
}
}