Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class 9
- {
- public static void main(String[] args)
- {
- Scanner stdIn = new Scanner(System.in);
- String[] roomList = new String[7]; //hotel room numbers
- int filledElements = 0; // number of hotel rooms
- String roomNum; //entered hotel room number
- System.out.print("Enter hotel room number (or q to quit): ");
- roomNum = stdIn.nextLine();
- while (!roomNum.equalsIgnoreCase("q") &&
- filledElements < roomList.length)
- {
- if (roomNum.length() < 1 || roomNum.length() > 6)
- {
- System.out.println("Invalid entry." + "Must enter between 1 and 16 characters.");
- }
- else
- {
- roomList[filledElements] = roomNum;
- filledElements++;
- }
- System.out.print("Enter hotel room number (or q to quit): ");
- roomNum = stdIn.nextLine();
- } //end while
- System.out.println("\n The Occupied rooms:");
- for (int i=0; i<filledElements; i++)
- {
- System.out.println((i + 1) + ". " + roomList[i]);
- } //end for
- public static void main (int[] args)
- {
- Scanner stdIn = new Scanner(System.in);
- int [] rooms= {1,56,19,160,34,18};
- OccupiedRoom = new room(ids,ids.length);
- int id; //room being searched for
- int index; //Room number sought or -1 if not found
- System.out.print("Please enter a hotel room number, -1 to quit: ") ;
- id = stdIn.nextInt();
- index = room.findroom(id) ;
- if (index >= 0)
- {
- System.out.println("Room is occupied " + index) ;
- }
- else
- {
- System.out.println("room is free");
- }//end main
- } //end class 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement