Я хочу иметь возможность динамически создавать объект сотрудника из пользовательского ввода. У меня уже есть два разных класса, один из которых - менеджер, а другой - сотрудник. Я должен иметь возможность указать, какого типа сотрудника я хочу создать, а также имя и возраст сотрудника. Как я могу это сделать?
while (true){
System.out.print("Input the type of employee: ");
String type = Input.next();
//Can only be "manager" or "associate"
System.out.print("Input the name of the employee: ");
String name = Input.next();
System.out.print("Input the age of the employee: ");
int age = Input.nextInt();
/*The name of the object should also be the name of the employee
*Depending on what "Type" is given from the user determines what type of object the new object is going to be
*/
type name = new type(name,age)
//type is not the reference type but a variable holding the reference *type
*/
}
Я ожидаю, что смогу создать столько объектов, сколько захочу, любого типа ссылки: менеджер или сотрудник. С разными именами и возрастами