所以我需要做的就是能够从文本文件中搜索房间,并显示与我搜索的内容相关的任何匹配项。代码运行良好的问题(房间类型,最低和最高价格,阳台和休息室),但最后,它所做的只是采取文本文件中的第一个房间,并将值更改为我搜索的, (显然我只想找到房间,而不是改变它们的任何内容)。不知道我哪里出错了,为什么它只找到第一个房间并在我不想要的时候改变它。任何帮助将不胜感激,谢谢!
private static void reserveRoom() throws FileNotFoundException {
Scanner s = new Scanner (System.in);
Scanner ROOMS = new Scanner (new FileReader("rooms.txt"));
int roomnumber = ROOMS.nextInt();
String roomtype = ROOMS.next();
double roomprice = ROOMS.nextDouble();
Boolean hasbalcony = ROOMS.nextBoolean();
Boolean haslounge = ROOMS.nextBoolean();
System.out.println(" ");
System.out.println("--Seach Rooms--" + "\n");
System.out.println("Room Type (Single/Double/Suite):");
roomtype = s.nextLine();
System.out.println(" ");
System.out.println("Minimum Price: ");
roomprice = s.nextDouble();
System.out.println(" ");
System.out.println("Highest Price: ");
roomprice = s.nextDouble();
System.out.println(" ");
System.out.println("Balcony Preferred?: ");
hasbalcony = s.nextBoolean();
System.out.println(" ");
System.out.println("Has Lounge?: ");
haslounge = s.nextBoolean();
System.out.println(" ");
System.out.println("Searching...");
System.out.println(" ");
System.out.printf("Room Number: %s, Room Type: %s, Room Price: £%.2f, Has Balcony: %s, Has Lounge: %s" + "\n", roomnumber, roomtype, roomprice, hasbalcony, haslounge);
System.out.println("--------------------------------------------------------------------------------------------------- " + "\n");