我正在尝试制作一个小应用程序,向用户显示菜单并进行选择。到目前为止,我有这个:
package hotel;
import java.util.*;
public class Hotel {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Room[] myHotel = new Room[10];
myHotel[0] = new Room ();
myHotel[1] = new Room ();
myHotel[2] = new Room ();
myHotel[3] = new Room ();
myHotel[4] = new Room ();
myHotel[5] = new Room ();
myHotel[6] = new Room ();
myHotel[7] = new Room ();
myHotel[8] = new Room ();
myHotel[9] = new Room ();
String roomName;
String menuEntry;
int roomNum = 0;
String[] hotel = new String[11];
for (int x = 0; x < 6; x++ ) hotel[x] = "";
initialise(hotel);
System.out.println("Enter one of the following:\nA) Add\nD)\nE)\nF)\nL)\nO)\nS)\nV) View all rooms\nInput:");
menuEntry = input.next();
if (menuEntry == "A")
{
while ( roomNum < 11 )
{
for (int x = 0; x < 10; x++ )
{
if (hotel[x].equals("e"))System.out.println("room " + x + " is empty");
}
System.out.println("Enter room number (0-9) or 10 to stop:" );
roomNum = input.nextInt();
System.out.println("Enter name for room " + roomNum +" :" ) ;
roomName = input.next();
hotel[roomNum] = roomName ;
}
}
if (menuEntry == "V")
{
for (int x = 0; x < 10; x++ )
{
System.out.println("room " + x + " occupied by " + hotel[x]);
}
}
}
private static void initialise( String hotelRef[] ) {
for (int x = 0; x < 10; x++ ) hotelRef[x] = "empty";
System.out.println( "initilise\n");
}
}
显示菜单,但是当输入一个条目时,循环结束并且#34;内置成功&#34;显示。
任何帮助表示赞赏:)