Epic Systems Interview Question
SDE-2sCountry: United States
Interview Type: In-Person
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package tiffviewer;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author yoelhafyani
*/
public class NewClass {
public static void main(String[] args) {
String testCaseString = "Type:Employee\nname,age,salary\nAshok,36,20000\nKishor,30,15000\nBharath,25,30000";
try {
ArrayList<Object> ee = (ArrayList<Object>)getArrayListObject(getType(testCaseString),getArgumentType(testCaseString), testCaseString );
for(Object ob : ee ){
System.out.println(ob.toString());
}
} catch (IllegalArgumentException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static ArrayList<Object> getArrayListObject(String TypeName, String Attributes[], String testCaseString) {
ArrayList<Object> objs = new ArrayList<Object>();
String[] data = testCaseString.split("\n");
for (int i = 2; i < data.length; i++) {
System.out.println(data[i]);
String[] DataValue = data[i].split(",");
try {
Class<?> c = Class.forName("tiffviewer." + getType(testCaseString));
Object obj = c.newInstance();
for (int j = 0; j < Attributes.length; j++) {
Class[] cArg = new Class[1];
cArg[0] = c.getDeclaredField(Attributes[j].toLowerCase().trim()).getType();
Method lMethod;
lMethod = c.getDeclaredMethod("set" + Capitalize(Attributes[j]), cArg);
if (cArg[0].getName() == "java.lang.String"){
lMethod.invoke(obj, DataValue[j]);
}else{
lMethod.invoke(obj, Integer.parseInt(DataValue[j]));
}
}
objs.add(obj);
}catch (ClassNotFoundException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}catch(IllegalArgumentException ex){
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}catch(IllegalAccessException ex){
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}catch(NoSuchMethodException ex){
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}catch(InvocationTargetException ex){
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}catch(InstantiationException ex){
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}catch(NoSuchFieldException ex){
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
return objs;
}
public static String Capitalize(String input){
return input.substring(0, 1).toUpperCase() + input.substring(1);
}
public static String getType(String testCaseString) {
return testCaseString.split("\n")[0].split(":")[1].trim();
}
public static String[] getArgumentType(String testCaseString) {
return testCaseString.split("\n")[1].split(",");
}
}
Hey
- Anonymous March 04, 2014Was this question asked in usa? I thought the onsite did not consist of technical questions.