I am trying to put a menu in to my hotel program to achieve the following:
i want to put the code that Views All rooms and Adds customer to room,
into separate procedures(methods) just to see if it will work. as this would make my main program simpler as it would jump to do this method then the next etc..
I want a menu system so the user can select what they want. for example what i have thought of doing is
Enter an A to add a customer to a room,
a V to view all rooms so When an A is pressed it should do the Add procedure, or a V should do the View procedure
E: Display Empty rooms,
D: Delete customer from room,
F: Find room from customer name,
S: Store program data in to file,
L: Load program data from file.
O: View rooms Ordered alphabetically by name.
Can anyone help me.. i know i have to use a switch statement but im a little stuck.. i have been going through tutorials but i cant seem to get i need.
the code for the main program is
and for the class
i want to put the code that Views All rooms and Adds customer to room,
into separate procedures(methods) just to see if it will work. as this would make my main program simpler as it would jump to do this method then the next etc..
I want a menu system so the user can select what they want. for example what i have thought of doing is
Enter an A to add a customer to a room,
a V to view all rooms so When an A is pressed it should do the Add procedure, or a V should do the View procedure
E: Display Empty rooms,
D: Delete customer from room,
F: Find room from customer name,
S: Store program data in to file,
L: Load program data from file.
O: View rooms Ordered alphabetically by name.
Can anyone help me.. i know i have to use a switch statement but im a little stuck.. i have been going through tutorials but i cant seem to get i need.
the code for the main program is
import java.util.*; public static void main(String[] args) { Scanner input = new Scanner(System.in); String roomName; int roomNum = 0; String[] hotel = new String[7]; //for (int x = 0; x < 6; x++ ) hotel[x] = ""; //initialise initialise(hotel); //better to initialise in a procedure while ( roomNum < 6 ) { for (int x = 0; x < 6; x++ ) { if (hotel[x].equals("e"))System.out.println("room " + x + " is empty"); } System.out.println("Enter room number (0-5) or 6 to stop:" ) ; roomNum = input.nextInt(); System.out.println("Enter name for room " + roomNum +" :" ) ; roomName = input.next(); hotel[roomNum] = roomName ; for (int x = 0; x < 6; x++ ) { System.out.println("room " + x + " occupied by " + hotel[x]); } } } private static void initialise( String hotelRef[] ) { for (int x = 0; x < 6; x++ ) hotelRef[x] = "e"; System.out.println( "initilise "); }
and for the class
public class Room { String mainName; //private String mainName; int guestsInRoom; public Room() { mainName = "k"; System.out.println("made a room "); } public void setName(String aName) { System.out.println("add name class method "); mainName = aName; } public String getName() { return mainName; } }