Jump to content

» «

need help with java validation

1 reply to this topic
  • deathdealer


  • Members
  • Joined: 25 Feb 2007
  • None


Posted 19 November 2013 - 04:45 PM

To be more precise, I need help with invoke a single validation method that is located in another class. here's a basic layout of the code:


public static void employeenumsearch(this is inside my main class){


String empnum = new String ("");
  String input = new String("");
  int choice = 0;
   boolean found = false;
   voterssn = JOptionPane.showInputDialog(" enter a employee number to search:");

   for (int i = 0; i < count; i++) {
   if (empnum.equals(vr[i].number)) {
   found = true;

   if (!found){
   JOptionPane.showMessageDialog(null, "the employee is not found. please search for another employee");






class employee{

//insert string definition and employee constructor here.




//code like employee name, age, and NUMBER are here


input = JOptionPane.showInputDialog("Enter employee number: ");
  while(checkSSN(input) == false)
   input = JOptionPane.showInputDialog("Invalid number input!: ");
  }//end while

}//end getemp


validatenumber(String input){


//validation code goes here


}//end validation


}//end class



so, how do I invoke that single validation method to the main class?



  • alias23

    Player Hater

  • Joined: 29 Nov 2013


Posted 29 November 2013 - 12:52 AM

you would simply do it like that:


public class Main{


private String s;

public static static void main(String[] args)
    employee e = new employee();


- create an object from the employee class and make a reference to it

- call the method from the class



You should name your classes starting with a capital letter and


most likely your method should look something like that: 


public int validatenumber(String input){   

//int num = Integer.parseInt(input);

return num;



if u wanted to make it threaded do it this way:


public class Main implements Runnable{

    private String s;
    public void run() {
        employee e = new employee();
        String print = e.validatenumber(s);    
    public static void main(String[] args)
        SwingUtilities.invokeLater(new Main());


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users