I have an employee class and I need to randomly assigned employees to a different groups (total 4) I never used random class before any ideas how to implement it.
public class EmployeeTest {
public static void main(String[] args) {
Random random = new Random();
int group_num = random.nextInt(30);
int max =0;
if(max > 4) {
group_num = 1;
ArrayList<Employee> emp = new ArrayList();
//for(int cnt = 1; cnt<4; cnt++) {
//if(emplo)
emp.add(new Employee("Tom", "Technology", 56, 34, 46, 23));
emp.add(new Employee("Nick", "Technology", 65, 33, 21, 23));
emp.add(new Employee("Jerry", "Technology", 56, 34, 46, 23));
emp.add(new Employee("Janet", "Technology", 56, 34, 46, 23));
emp.add(new Employee("Chitra", "Trading", 12, 54, 46, 23));
emp.add(new Employee("Sally", "Trading", 16, 64, 46, 23));
for(Employee e : emp) {
// Random random = new Random();
// int group_num = random.nextInt(30);
// int max =0;
// if(max > 4) {
// group_num = 1;
}
System.out.println("Employee | identifier: " + e.getUnicIdentifier() + ", department: " + e.getDepartment() + ", texh_exp: " + e.getTech_exp() + " , trade_exp: " + e.getTrade_exp() +
" , op_exp: " + e.getOp_exp() + ", shared_exp: " + e.getShared_exp() + ", group_num: " + group_num);
}
Aucun commentaire:
Enregistrer un commentaire