public class Employee {
private String name;
public Employee(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public class Manager extends Employee{
public Manager(String name){
super(name);
}
}
public class Secretary extends Employee {
public Secretary(String name) {
super(name);
}
}
import java.util.Random;
public class Main {
public static void main(String[] args) {
Employee[] employees = new Employee[20];
String[] names = {"Tom", "Lisa", "Bob", "Roger", "Tim", "Leo", "Nick", "David", "Sarah", "Lucie"};
for (int i = 0; i < names.length; i++) {
employees[i] = new Random().nextBoolean() ?
(new Random().nextBoolean() ? new Manager(names[i]) : new Employee(names[i]))
: new Secretary(names[i]);
}
for (int i = 0; i < names.length; i++) {
System.out.println(employees[i].getName());
}
}
}
Comments
Leave a comment