Question: I developed a simple room reservation with Java IDE : Eclipce, source code as below I'm failed to performed functions as per below Cannot add

I developed a simple room reservation with Java

IDE : Eclipce, source code as below

I'm failed to performed functions as per below

  1. Cannot add on customer phone number , number of guest (max of 10),
  2. Cannot create new file
  3. Cannot extract new file
  4. Cannot sort the file

Please ignore the file pathways as i copied it from stack overflow

Kindly assist.

package Reservation_System_CKL;

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.Arrays;

import java.util.Scanner;

public class Reservation_system {

private static boolean MainMenu = true;

private static boolean SubMenu = true;

public static void main(String[] args) throws IOException {

@SuppressWarnings("resource")

Scanner input = new Scanner(System.in);

Room[] availableRoom = new Room[10];

availableRoom[0] = new Room();

availableRoom[1] = new Room();

availableRoom[2] = new Room();

availableRoom[3] = new Room();

availableRoom[4] = new Room();

availableRoom[5] = new Room();

availableRoom[6] = new Room();

availableRoom[7] = new Room();

availableRoom[8] = new Room();

availableRoom[9] = new Room();

int roomNum = 0;

initialise(availableRoom);

while (MainMenu) {

while (SubMenu) {

System.out.println("***************************************************************************************");

System.out.println("------------***~~~**** Customer Studio Reservation Record *****~~~****-----------------");

System.out.println("**");

System.out.println("*Remind customer to take off the shoes*");

System.out.println("*Use sanitazer before entering the room*");

System.out.println("**");

System.out.println("**");

System.out.println("**");

System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

System.out.println("PLEASE SELECT ANY OPTION BELOW TO CONTINUE");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("A: Book A New Room.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("E: Display Empty Rooms.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("V: View all Rooms.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("D: Delete customer from room.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("F: Find room from customer name.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("S: Store program data in to file.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("L: Load program data from file.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("O: View rooms Ordered alphabetically by name.");

System.out.println("---------------------------------------------------------------------------------------");

System.out.println("***************************************************************************************");

String Selection = input.next();

Selection = Selection.toUpperCase();

switch (Selection) {

case "A":

BookARoom(availableRoom, roomNum);

break;

case "a":

BookARoom(availableRoom, roomNum);

break;

case "E":

CheckIfEmpty(availableRoom);

break;

case "e":

CheckIfEmpty(availableRoom);

break;

case "V":

ViewAllRooms(availableRoom);

break;

case "v":

ViewAllRooms(availableRoom);

break;

case "D":

DeleteCustomerFromRoom(availableRoom, roomNum);

break;

case "d":

DeleteCustomerFromRoom(availableRoom, roomNum);

break;

case "F":

FindRoomFromCustomerName(availableRoom);

break;

case "f":

FindRoomFromCustomerName(availableRoom);

break;

case "S":

StoreProgramDataInToFile(availableRoom);

break;

case "s":

StoreProgramDataInToFile(availableRoom);

break;

case "L":

LoadProgramDataFromFile(availableRoom);

break;

case "l":

LoadProgramDataFromFile(availableRoom);

break;

case "O":

ViewRoomsOrderedAlphabeticallyByName(availableRoom);

break;

case "o":

ViewRoomsOrderedAlphabeticallyByName(availableRoom);

break;

default:

System.out.println("Invalid Selection");

break;

}

System.out.println("******************************************************");

System.out.println("");

System.out.println("Any other action to performed ? 1 ) Yes, view the menu 2 ) No, I want to EXIT");

System.out.println("");

System.out.println("******************************************************");

if (input.nextInt() == 1) {

SubMenu = true;

} else {

SubMenu = false;

}

}

SubMenu = true;

System.out.println("******************************************************");

System.out.println("");

System.out.println("Are you sure to exit ? 1 ) Yes 2 ) No");

System.out.println("");

System.out.println("******************************************************");

if (input.nextInt() == 1) {

MainMenu = true;

} else {

System.out.println("");

System.exit(0);

}

}

}

private static void initialise(Room[] availableRoom) {

for (int x = 0; x < availableRoom.length; x++) {

availableRoom[x].setName("vacancy");

}

}

private static void CheckIfEmpty(Room[] availableRoom) {

for (int x = 0; x < availableRoom.length; x++) {

if (availableRoom[x].getName().equals("vacancy")) {

System.out.println("room " + (x + 1) + " is vacancy");

}

}

}

private static void BookARoom(Room[] availableRoom, int roomNum) {

String roomName;

@SuppressWarnings("resource")

Scanner input = new Scanner(System.in);

System.out.println("Enter room number (1-10):");

roomNum = input.nextInt() - 1;

System.out.println("Enter name for room " + (roomNum + 1) + " :");

roomName = input.next();

availableRoom[roomNum].setName(roomName);

}

private static void ViewAllRooms(Room[] availableRoom) {

for (int x = 0; x < availableRoom.length; x++) {

System.out.println("room " + (x + 1) + " occupied by " + availableRoom[x].getName());

}

}

private static void DeleteCustomerFromRoom(Room[] availableRoom, int roomNum) {

@SuppressWarnings("resource")

Scanner input = new Scanner(System.in);

System.out.println("Enter room number to delete(1-10):");

roomNum = input.nextInt() - 1;

availableRoom[roomNum].setName("vacancy");

System.out.println("Entery Deleted :)");

}

private static void FindRoomFromCustomerName(Room[] availableRoom) {

@SuppressWarnings("resource")

Scanner input = new Scanner(System.in);

String roomName;

System.out.println("Enter name to Search for:");

roomName = input.next();

int x;

boolean Checker = false;

for (x = 0; x < availableRoom.length; x++) {

if (roomName.equals(availableRoom[x].getName())) {

System.out.println("The Account That Matches the name is Account number " + x);

Checker = true;

}

}

if (Checker == false) {

System.out.println("There are no Rooms Booked with that name (make sure you've key-ed in the correct name)");

}

}

private static void StoreProgramDataInToFile(Room[] availableRoom) throws IOException {

try (PrintWriter out = new PrintWriter(new FileWriter("/home/unix/student12/w1387769/outputfile.txt"))) {

int x;

for (x = 0; x < availableRoom.length; x++) {

out.println("Name and Room number is: " + availableRoom[x].getName() + "at: " + x);

}

}

System.out.println("All Room Names have been Saved.");

}

private static void LoadProgramDataFromFile(Room[] availableRoom) throws IOException {

FileInputStream fs = new FileInputStream("/home/unix/student12/w1387769/inputfile.txt");

@SuppressWarnings("resource")

BufferedReader br = new BufferedReader(new InputStreamReader(fs));

for (int i = 0; i < availableRoom.length; i++) {

availableRoom[i].setName(br.readLine());

}

}

private static void ViewRoomsOrderedAlphabeticallyByName(Room[] availableRoom) {

String[] myStrArray = new String[availableRoom.length];

for (int i = 0; i < availableRoom.length; i++)

{

myStrArray[i] = availableRoom[1].getName();

}

Arrays.sort(myStrArray);

for (int a = 0; a < myStrArray.length; a++)

{

System.out.println(myStrArray[a]);

}

}

public static class Room {

//protected String mainName;

private String mainName;

int guestsInRoom;

public Room() {

mainName = "k";

}

public void setName(String aName) {

//System.out.println("add name class method ");

mainName = aName;

}

public String getName() {

return mainName;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!