我希望界面在完成命令后返回“输入命令”菜单(除非用户输入“退出”),但它会一遍又一遍地重复该命令的相同界面。例如,当用户输入“注册”时,系统应询问姓名,然后是电话号码,然后是电子邮件地址,然后说已创建了工作人员(给定用户输入正确的输入类型)。然后系统应该要求另一个命令,但它会询问姓名,电话号码和电子邮件地址,并将注册另一名工作人员。请帮帮忙?
public static void main(String args[]){
RoomBookSystem rbs = new RoomBookSystem();
//add rooms to the system
Room room1=new Room();
Room room2=new Room();
Room room3=new Room();
Room room4=new Room();
room1.setName("1");
room1.setCapacity(247);
room1.setEquipment("Projector");;
room1.setID(2);
room2.setName("2");
room2.setCapacity(18);
room2.setEquipment("Waffle maker, television");
room2.setID(2);
room3.setName("3");
room3.setCapacity(10);
room3.setEquipment("Television");
room3.setID(3);
room4.setName("4");
room4.setCapacity(12);
room4.setEquipment("Piano");
room1.setID(4);
rbs.addRoom(room1);
rbs.addRoom(room2);
rbs.addRoom(room3);
rbs.addRoom(room4);
//adds staff to the system
Staff kai = new Staff();
Staff sehun = new Staff();
Staff xiumin = new Staff();
Staff chen = new Staff();
kai.setName("Kai");
kai.setPhoneNumber("123456789");
kai.setEmailAddress("kai@exo.com");
sehun.setName("Sehun");
sehun.setPhoneNumber("6758302");
sehun.setEmailAddress("yehet@exo.com");
xiumin.setName("Xiumin");
xiumin.setPhoneNumber("90");
xiumin.setEmailAddress("xiurista@exo.com");
chen.setName("Chen");
chen.setPhoneNumber("609090900");
chen.setEmailAddress("chensingmachine@exo.com");
rbs.registerStaff(kai);
rbs.registerStaff(xiumin);
rbs.registerStaff(sehun);
rbs.registerStaff(chen);
//Starts the room booking interface
System.out.println("*************************************************");
System.out.println("Welcome to the room booking system!");
System.out.println("*************************************************");
System.out.println("The following rooms are available: ");
rbs.printRooms();
System.out.println("-------------------------------------------------");
System.out.println("Enter a command: (register, book, rooms, print, cancel, exit)");
Scanner scan = new Scanner(System.in);
String userCommand = scan.nextLine();
//while(userCommand!="exit"){
while(userCommand=="register"){
System.out.println("enter your name: ");
Staff newStaff = new Staff();
String name = scan.nextLine();
newStaff.setName(name);
System.out.println("Enter your email address: ");
String emailAddress = scan.nextLine();
newStaff.setEmailAddress(emailAddress);
System.out.println("Enter your phone number");
String phoneNumber=scan.nextLine();
newStaff.setPhoneNumber(phoneNumber);
rbs.registerStaff(newStaff);
System.out.println("Staff member: "+name+", "+emailAddress+", "+phoneNumber+" has been registered");
} if(userCommand=="book"){
System.out.println("Booking a new meeting: ");
System.out.println("Enter staff name");
String staffName = scan.nextLine();
if(rbs.isRegistered(staffName)){
Staff staffBooker = new Staff();
for(int i =0; i<rbs.currentStaff.length;i++){
if(rbs.currentStaff[i].getName()==staffName){
staffBooker=rbs.currentStaff[i];
}
Room newRoom = new Room();
System.out.println("Enter a room ID: ");
int roomID = scan.nextInt();
System.out.println("Enter a month: ");
int month= scan.nextInt();
System.out.println("Enter day: ");
int day = scan.nextInt();
System.out.println("Enter starting hour: ");
int startingHour=scan.nextInt();
System.out.println("Enter duration: ");
int duration = scan.nextInt();
newRoom.setID(roomID);
TimeInterval newTimeInterval = new TimeInterval(startingHour,day,month,duration);
Meeting newMeeting = new Meeting(staffBooker, newTimeInterval, newRoom);
rbs.bookMeeting(newMeeting);
}
}
} else if(userCommand=="rooms"){
Room newRoom = new Room();
System.out.println("Add a new room");
System.out.println("Enter room ID: ");
int roomID = scan.nextInt();
System.out.println("Enter room capacity: ");
int roomCapacity = scan.nextInt();
System.out.println("Enter equipment available in room: ");
String equipment = scan.nextLine();
newRoom.setID(roomID);
newRoom.setCapacity(roomCapacity);
newRoom.setEquipment(equipment);
rbs.addRoom(newRoom);
} else if(userCommand=="print"){
rbs.printRooms();
rbs.printMeeting();
rbs.printStaff();
scan.close();
System.out.println("Goodbye");
System.exit(0);
}
}
答案 0 :(得分:0)
请你把(usercomman == register)更改为if语句并试一试吗?