Hi, im new in java. I am doing the home work to create a mini hotel reservation system which should be able to write the data into .txt file.
case study:
1. Have 2 different types of room (1- Suite 2- Deluxe)
2. Room Rate (Suite - $500per night, Deluxe - $300per night)
3. Both rooms can accomodate 2adults and 2childs
4. Checkin time: 2pm, Checkout 11am
5. Room status = occupied once guest checkin, Room status = vacant once guest checkout
6.For checking require (ID,Full Name,Address,Nationality,Flight no/Vehicle Reg no,number of people,check-in date, check-out-date,payment detail
7.Front desk search the vacant room to be assigned to the guest
Functions:
1. View all rooms
2. Add Customer to a room
3. Display available room
4. Delete customer from a room
5. Find room from customer name
6. Exit
Files:
One file use to store room info. (to be retrieved by program)
One file use to store rate info. (to be retrieve by program)
One file use to store the booking details (to be created and write by the program).
Currently I have write a program but only compiling and display the output to the console. Could somebody help me to modify my code below to be able to save to the .txt file
Here is the code:
----------------
import java.util.*;
import java.io.*;
class Customer
{
private String name;
private int room;
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return this.name;
}
public void setRoom(int room)
{
this.room=room;
}
public int getRoom()
{
return this.room;
}
}
class Hotel
{
public static void initialize(Customer RoomList[])
{
for(int i=0; i<RoomList.length; i++)
{
RoomList[i]=new Customer();
RoomList[i].setName("EMPTY");
RoomList[i].setRoom(i+1);
}
}
public static void viewList(Customer RoomList[])
{
for(int i=0; i<RoomList.length; i++)
{
if(RoomList[i].getName()=="EMPTY")
System.out.println("Room number "+RoomList[i].getRoom()+" is vacant.");
else
System.out.println("Room number "+RoomList[i].getRoom()+" is ocupied by "+RoomList[i].getName()+".");
}
System.out.println();
}
public static boolean addCustomer(Customer RoomList[], String name)
{
for(int i=0; i<RoomList.length; i++)
if(RoomList[i].getName().equals("EMPTY"))
{
RoomList[i].setName(name);
return true;
}
return false;
}
public static void showEmptyRooms(Customer RoomList[])
{
System.out.println("Available rooms are:");
for(int i=0; i<RoomList.length; i++)
if(RoomList[i].getName()=="EMPTY")
System.out.println(RoomList[i].getRoom());
System.out.println();
}
public static boolean deleteCustomer(Customer RoomList[], String name)
{
for(int i=0; i<RoomList.length; i++)
if(RoomList[i].getName().equals(name))
{
RoomList[i].setName("EMPTY");
System.out.println("Deletion successful.\n");
return true;
}
return false;
}
public static int getIndex(Customer RoomList[], String name)
{
for(int i=0; i<RoomList.length; i++)
if(RoomList[i].getName().equals(name))
return i;
return -1;
}
public static void main(String[] args)
{
// File f=new File("C:/TestHotel.txt");
Customer[] RoomList = new Customer[12];
String name;
initialize(RoomList);
Scanner input = new Scanner(System.in);
int option=0;
do
{
System.out.println(" Hotel Booking Options");
System.out.println("============================== =======");
System.out.println("1: To View all rooms");
System.out.println("2: To Add customer to a room");
System.out.println("3: To Display empty rooms");
System.out.println("4: To Delete customer from a room");
System.out.println("5: Find room from customer name");
System.out.println("0: Exit");
System.out.print("\nEnter your choice: ");
option = input.nextInt();
System.out.println();
switch(option)
{
case 1:
{
viewList(RoomList);
break;
}
case 2:
{
System.out.print("Customer's name: ");
name=input.next();
System.out.println();
if(!addCustomer(RoomList, name))
System.out.println("No rooms available!");
break;
}
case 3:
{
showEmptyRooms(RoomList);
break;
}
case 4:
{
System.out.print("Customer's name: ");
name=input.next();
System.out.println();
deleteCustomer(RoomList, name);
break;
}
case 5:
{
System.out.print("Customer's name: ");
name=input.next();
System.out.println();
System.out.println("Customer's room: "+RoomList[getIndex(RoomList, name)].getRoom()+"\n");
break;
}
case 0:
{
System.out.println("\nThank you!\n");
break;
}
default:
{
System.out.println("Invalid option!\n");
break;
}
}
}while(option!=0);
}
}