Hey there,

Just hit a road block in my assignment. I won't concern you too much with the assignment itself but it's basically a number input operated menu with option's like "Display employee details" & "Input pay details."

I'm up to a part where I need to get the section "Create Employee ID" working. Basically what it want's me to do is add a method to the class (MyString.java - seperate file to main assignment) called 'CreateID()' and this method's job is to accept lastName as a parameter and return it as a string to the empID() field. I'm using substring to take the first three characters from the lastName field and adding a random number between 1200 - 1299 to these letters to create an 'Employee ID.' So far I have this for the method:

public class MyString
{
   public static String createID(C)
   {
      String message = C.substring(0.3).toUpperCase();
      return message += (int) (Math.random()*99 + 1200);
   }    

}

Firstly I'd like to know if you see anything wrong with the above code, because it looks okay to me. For example, it will take the first three characters from the last name "Johnson" and add a random number between 1200-1299 so that it will look like JOH1288 - and that will serve as the employee ID.

Now I'm having trouble with calling this method in the main assignment file. Here's the filler text for where the code I'm missing should go:

public static void createEmpID()
    {
        JOptionPane.showMessageDialog(null,"In (2) createEmpID()");
    }

All it does right now is obviously show the text within the quotation marks - I need the code that will call the method from the MyString.java file.

I'm not that great with Java so please be as descriptive as possible when answering, thank you!

Recommended Answers

All 2 Replies

have you tried

public static void createEmpID()
    {
        JOptionPane.showMessageDialog(null,MyString.createEmpID(lastName));
    }

?

public static String createID(C)
That won't compile becuase when you define a method you have to say what type the parameter is. You can save a lot of time by trying to compile your code and fixing as many errors as you can before posting here and waiting for someone to respond.

@dimaselang, @sephzy: showMessageDialog is not the one you need - it just displays a message. you could use showInputDialog which has a place for the user to type input and returns that input to you as a String that you can then pass to createEmpID.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.