我想調用一個具有特定名稱的對象,並將其輸入控制檯。 我知道一種方法將與switch語句,但它也應該與新的初始化對象。請求輸入一個已初始化的對象
這裏是一個代碼示例。
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String nameObject=null;
// Create a new Object with a specific name
System.out.println("Type in the name of the Object");
try {
nameObject = reader.readLine();
} catch (IOException e) {
}
Person NewPerson = new Person(nameObject);
System.out.println("Which Person do you want to have?");
String requestName = reader.readLine();
//search for the object which has the name requestName
// after this i want find the right person with an reader.??
弄來的nameObject變量什麼價值? – xFighter
是的,我要求提供成爲新對象名稱的人的姓名。初始化工作正常的問題是,當我有幾個人的對象,我想打一個具體的名字。 –
你可以顯示你的Person類嗎? – xFighter