Quantcast

Jump to content

» «
Photo

need help with java validation

1 reply to this topic
deathdealer
  • deathdealer

    The Yardies

  • The Yardies
  • Joined: 25 Feb 2007

#1

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.

 

getemp(){

 

//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
  • alias23

    Player Hater

  • BUSTED!
  • Joined: 29 Nov 2013

#2

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();
    e.validatenumber(s);
}

 

- 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;
    
    @Override
    public void run() {
        employee e = new employee();
        String print = e.validatenumber(s);    
        System.out.println(print);
    }
    
    
    public static void main(String[] args)
    {        
        SwingUtilities.invokeLater(new Main());
    }

}





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users