Hi,
I am trying to do a hotel system where i have written up this code, however i was wondering if the there was a way to make the main program simple.
So what im trying to do is the code that ‘Views All rooms’ and ‘Adds customer to room’, put them into separate procedures and a menu so When i press ‘A’ is it will do the Add
procedure, and when i press ‘V’ the View procedure.
Below is the code i have written. I would really appreciate if anyone can help me
`package reservation;
import java.util.*;
/**
*
* @author alex
*/
public class reservation {package reservation;
import java.util.*;
/**
*
* @author alex
*/
public class reservation {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
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 )
{
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 ");
Scanner input = new Scanner(System.in);
Room[] myHotel = new Room[4];
myHotel[0] = new Room();
myHotel[1] = new Room();
myHotel[2] = new Room();
myHotel[3] = new Room();
String roomName;
int roomNum = 0;
initialise(myHotel);
while (roomNum < 4) {
for (int x = 0; x < 4; x++ )
if (myHotel[x].mainName.equals("e"))System.out.println("room " + x + " is empty");
System.out.println("Enter room number (0-3) or 4 to stop:"); //error with 4
roomNum = input.nextInt();
System.out.println("Enter name for room " + roomNum + " :");
roomName = input.next();
myHotel[roomNum].mainName = roomName ;
// myHotel[roomNum].setName(roomName);
for (int x = 0; x < 4; x++) {
System.out.println("room " + x + " occupied by " + myHotel[x].mainName);
// System.out.println("room " + x + " occupied by " + myHotel[x].getName());
}
}
}
private static void initialise( Room hotelRef[] ) {
for (int x = 0; x < 4; x++ ) hotelRef[x].mainName = "e";
System.out.println( "initilise ");
}}