0

equals() How do I write a proper comparison for empId and empN? The code needs to print random generated empId.

public boolean equals(empId empN){
if (this.empId.equals(empN));
Random num = new Random();//Random Number Generator
int upperbound = 9;//Generates random numbers 0 - 9
int int_random = num.nextInt(upperbound);
return "Employee ID:" +empId+ "Employee Name:" +empN;
  • No. The code suggested compared to variables pointing to the same memory address. My code needs to compare two variables and generate a Random employee number. The employee number will of course identify the employee.. – TritonEng Mar 01 '20 at 03:14
  • The equals method is not where you choose an employee ID at random; the method returns a boolean (either true or false, not a string), where true if the two objects (`this` and the object passed in) are "equal", or false if not. – Peter O. Mar 01 '20 at 03:29
  • It seems that your goal is to generate random employee IDs and ensure they are unique. I have written [more information](https://peteroupc.github.io/random.html#Unique_Random_Identifiers) on generating unique IDs. – Peter O. Mar 01 '20 at 03:33

0 Answers0