I'm a newbie and just started Computer Science, we we're tasked to do this simple program and I'm having a problem I don't really know how to make a way around. Says that "decision" was not initialized, but using the quick fix (initializing the variable) makes the String decision = null;
. Running this code then gives me this error Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.hashCode()" because "<local5>" is null at com.company.Main.main(Main.java:20)
. How do I fix this?
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
// input scanner
Scanner scn = new Scanner (System.in);
String empName;
System.out.print("Please enter the Employee name: ");
empName = scn.next();
String decision;
boolean FP = true;
while(FP)
{
System.out.print("Enter 'F' for Full Time or 'P' for Part Time: ");
switch (decision) {
case "F" -> FP = true;
case "P" -> FP = false;
}
}
if (FP = true)
{
System.out.println("---- Full Time Employee ----");
double monSal;
System.out.print("Enter monthly salary: ");
monSal = scn.nextDouble();
System.out.print(empName + monSal);
}
}
}