Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我运行java应用程序时遇到了问题,它可以';I don’我不能按预期执行_Java - Fatal编程技术网

我运行java应用程序时遇到了问题,它可以';I don’我不能按预期执行

我运行java应用程序时遇到了问题,它可以';I don’我不能按预期执行,java,Java,我的应用程序找不到我添加到房间中的室友,请参见顺序: Please select one of the following options: Add a room in the apartment[1] Search for a room in the apartment[2] Add a roommate to an existing room[3] Check if a room has a roommate[4] Count the number of existing rooms tha

我的应用程序找不到我添加到房间中的室友,请参见顺序:

Please select one of the following options:
Add a room in the apartment[1]
Search for a room in the apartment[2]
Add a roommate to an existing room[3]
Check if a room has a roommate[4]
Count the number of existing rooms that have roommates living in them[5]
3
What is the name of this roommate?
kack
What is the surname of thid roommata?
han
What is the age of this roommate?
20
Which room you want to add this roommate in?[A]/[B]/[C]
b
The roommate was added to the room!
Do you want to continue using the App? (Y/N)
y
Please select one of the following options:
Add a room in the apartment[1]
Search for a room in the apartment[2]
Add a roommate to an existing room[3]
Check if a room has a roommate[4]
Count the number of existing rooms that have roommates living in them[5]
4
What is the ID of the room?[A]/[B]/[C]
b
Sorry! There is no roommate in this room.
我不知道我要重写什么地方。我想知道哪一部分是错误的,我应该如何重写我的代码。代码如下,第一部分是添加室友,第二部分是检查房间中是否有室友:

public boolean addRoommate(字符串pName、字符串pSurname、int pAge、字符pID){
布尔响应=假;
if(roomA!=null&&roomA.getID()==(pID)){
室友newRoommate=新室友(pName、pSurname、pAge);
响应=真;
}else if(roomB!=null&&roomB.getID()==(pID)){
室友newRoommate=新室友(pName、pSurname、pAge);
响应=真;
}else if(roomC!=null&&roomC.getID()==(pID)){
室友newRoommate=新室友(pName、pSurname、pAge);
响应=真;
}
返回响应;
}
这是代码的第二部分,我在这里检查室友:

公共室友检查室友(char-pID){
室友反应=null;
if(roomA!=null&&roomA.getID()=(pID)&&roomA.getRoommate()!=null){
response=roomA.getRoommate();
}else if(roomB!=null&&roomB.getID()=(pID)&&roomB.getRoommate()!=null){
response=roomB.getRoommate();
}else if(roomC!=null&&roomC.getID()=(pID)&&roomC.getRoommate()!=null){
response=roomC.getRoommate();
}
返回响应;
}

您需要将rommate放入rool中,例如:

roomA.setRoomMate(newRoommate)

您没有将创建的室友放入任何房间,而是使用
新建
创建对象,然后再将其扔掉。我应该如何将室友放入房间?我不知道该怎么办。@Kristin Weng您需要在您的房间对象中添加室友列表。我的书写方式正确吗?它仍然告诉我房间里没有室友。如果(roomA!=null&&roomA.getID()=(pID)){Roommate newRoommate=newRoommate(pName,pSurname,pAge);roomA.setRoommate(newRoommate);response=true;}在调试器中逐行执行,则可以检查对象的内容。对于这段代码,我无法提供更多的帮助。