-1

My professor said that we need to input a letter to the dialog box in order for regular, probation etc. to show. I don't know how to resolve this problem. Is there something wrong? I'm new to java.

Here's my code:

import javax.swing.*;
public class EmployeeCode_input
{
    public static void main (String[]args)
    {
        char EC;
        EC=Character.parseChar(JOptionPane.showInputDialog("enter employee code"));
        if ((EC=="R")&&(EC=="r"))
            System.out.println("Regular");
        else if((EC=="P")&&(EC=="p"))
            System.out.println("Probationing");
        else if((EC=="T")&&(EC=="t"))
            System.out.println("Trainee");
        else if ((EC=="C")&&(EC=="c"))
            System.out.println("Contractual");
        else
            System.out.println("INVALID");
    }
}
Andrew Schuster
  • 3,229
  • 2
  • 21
  • 32

2 Answers2

2

Character.parseChar is not available in Java.

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
frost
  • 520
  • 1
  • 3
  • 13
0

As chinmay ghag pointed out there is no Character.parseChar in Java. You may use String's charAt() method instead.

Change :

EC=Character.parseChar(JOptionPane.showInputDialog("enter employee code"));

To :

EC=JOptionPane.showInputDialog("enter employee code").charAt(0);

See this for more information: How to convert/parse from String to char in java?

Also if EC is of type char then you shouldn't be comparing char's with strings. ie: EC = 'p' not EC = "p"

Community
  • 1
  • 1
James Martinez
  • 191
  • 2
  • 11