will there be another way to pass the exercise without using if loop? I have been testing using the "Class.forName" method, but have not got results.
Class<?> cl = Class.forName(key);
Person.cl person = Person.new cl();
System.out.println(person);
package com.codegym.task.task14.task1411;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
/*
User, loser, coder and programmer
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String key = null;
String[] casa = new String[]{"user", "loser", "coder", "programmer"};
ArrayList<String> estono = new ArrayList<String>();
estono.addAll(Arrays.asList(casa));
while (estono.contains(key = reader.readLine()))// Here's the loop for reading the keys. Item 1
{
// Create an object. Item 2
// use fully qualified name
//
Class<?> cl = Class.forName(key);
Person.cl person = Person.new cl();
System.out.println(person);
// System.out.println(person);
doWork(person);
// Call doWork
}
public static void doWork (Person person){
}
// Item 3
}
//}
}
}