This assignment should be done in 3 language just check and confirm

1 answer below »
This assignment should be done in 3 language just check and confirm
Answered Same DaySep 11, 2021

Answer To: This assignment should be done in 3 language just check and confirm

Robert answered on Sep 25 2021
144 Votes
44399/Java/src/HotelBookings.java
44399/Java/src/HotelBookings.java
import java.util.Scanner;
public class HotelBookings{
    public static String[] guestdtl = new String[1000];
    public static Integer[][] roomdtl = new Integer[1000][2];
    public static Integer[][] bookingdtl = new Integer[1000][5];
    public static void main(String[] args){
       menu();
    }
public static void menu(){
String a = "----------------------------------------"
                + "----------------------------------------";
        String b = "---------------------";
        System.out.println(a);
        System.out.println(b + "   Welcome to FedUni Hotel Bookings   " + b);
        System.out.println(a);
        System.out.println("Main Menu - Please Select an Option :");
        System.out.println("   1.) Add Guest");
        System.out.println("   2.) Add Room");
        System.out.println("   3.) Add Bookings");
        System.out.println("   4.) View Bookings");
        System.out.println("   5.) Quit");
        setinitialdata();
        start();
}
    private static void setinitialdata() {
        // Initialized array for testing
        guestdtl[0] = "NULL";
        guestdtl[1] = "James";
        guestdtl[2] = "William";
        guestdtl[3] = "Ella";
        roomdtl[0][0] = 98;
        roomdtl[0][1] = 2;
        roomdtl[1][0] = 99;
        roomdtl[1][1] = 3;
        roomdtl[2][0] = 102;
        roomdtl[2][1] = 5;
        roomdtl[3][0] = 200;
        roomdtl[3][1] = 1;
        roomdtl[4][0] = 201;
        roomdtl[4][1] = 2;
        bookingdtl[0][0] = 1;
        bookingdtl[0][1] = 98;
        bookingdt
l[0][2] = 2;
        bookingdtl[0][3] = 258;
        bookingdtl[0][4] = 260;
        bookingdtl[1][0] = 1;
        bookingdtl[1][1] = 200;
        bookingdtl[1][2] = 1;
        bookingdtl[1][3] = 290;
        bookingdtl[1][4] = 292;
        bookingdtl[2][0] = 2;
        bookingdtl[2][1] = 99;
        bookingdtl[2][2] = 3;
        bookingdtl[2][3] = 201;
        bookingdtl[2][4] = 202;
        bookingdtl[3][0] = 3;
        bookingdtl[3][1] = 102;
        bookingdtl[3][2] = 5;
        bookingdtl[3][3] = 168;
        bookingdtl[3][4] = 172;
        bookingdtl[4][0] = 3;
        bookingdtl[4][1] = 98;
        bookingdtl[4][2] = 2;
        bookingdtl[4][3] = 256;
        bookingdtl[4][4] = 260;
    }
    public static void start() {
        System.out.println("Please Enter an Option : ");
        Scanner ip1 = new Scanner(System.in);
        try {
            int input = ip1.nextInt();
            if (input == 1) {
                System.out.println();
                addguest();
            }
            if (input == 2) {
                System.out.println();
                addroom();
            }
            if (input == 3) {
                System.out.println();
                findguest();
            }
            if (input == 4) {
                System.out.println();
                views();
            }
            if (input == 5) {
                System.out.println();
                endprog();
            } else {
                System.out.println("\nPlease Select the Correct Option...");
                start();
            }
        } catch (Exception e) {
            System.out.println("Please Select the Correct Option...");
            start();
        }
    }
    public static void addguest() {
        System.out.println("Please Enter Guest Name below -");
        System.out.println("Guest Name: ");
        Scanner name = new Scanner(System.in);
        String guestName = name.nextLine();
        if(guestName.equals("")){
            System.out.println("Please Enter Valid Guest Name.\n");
            addguest();
        }
        else {
            int i = 0;
            for (int i1 = 0; i1 < guestdtl.length; i1++) {
                String s = guestdtl[i1];
                if (s != null) {
                    i++;
                }
            }
            System.out.println("Guest " + guestName.toUpperCase() + " has been created with Guest ID: " + i);
            guestdtl[i] = guestName.toUpperCase();
        }
        while (true){
            System.out.println("\nWould You like to [A]dd a new Guest or [R]eturn to the previous Menu ?");
            Scanner q1 = new Scanner(System.in);
            String a1 = q1.nextLine();
            if ((a1.toUpperCase()).equals("A")){
                System.out.println();
                addguest();
            }
            else if ((a1.toUpperCase()).equals("R")){
                System.out.println();
                System.out.flush();
                menu();
            }
            else{
                System.out.println("Invalid Input...");
                continue;
            }
        }
    }
    public static void addroom() {
        System.out.println("Please Enter Room Number -");
        Scanner irno = new Scanner(System.in);
        try {
            int rno = irno.nextInt();
            System.out.println("Please Enter Room Capacity -");
            Scanner ircap = new Scanner(System.in);
            try {
                int rcap = ircap.nextInt();
                if ((rno == 0) || (rcap == 0)) {
                    System.out.println("Please Enter Valid Room Number and Room Capacity.\n");
                    addroom();
                } else {
                    for (int r = 0; r < roomdtl.length; r++) {
                        Integer s = roomdtl[r][0];
                        if (s != null) {
                            int rn = roomdtl[r][0];
                            if (rno == rn) {
                                System.out.println("\nRoom Already Exists.");
                                addroom();
                            }
                        }
                    }
                    int i = 0;
                    for (int i1 = 0; i1 < roomdtl.length; i1++) {
                        Integer s = roomdtl[i1][0];
                        if (s != null) {
                            i++;
                        }
                    }
                    roomdtl[i][0] = rno;
                    roomdtl[i][1] = rcap;
                }
            } catch (Exception e) {
                System.out.println("Please Enter Valid Room capacity.");
                addroom();
            }
        } catch (Exception e) {
            System.out.println("Please enter Valid Room Number.");
            addroom(); }
        while (true) {
            System.out.println("\nWould you like to [A]dd a New Room OR [R]eturn to the Main Menu ?");
            Scanner q2 = new Scanner(System.in);
            String aq2 = q2.nextLine();
            if (aq2.toUpperCase().equals("A")) {
                System.out.println("");
                addroom();
            }
            else if (aq2.toUpperCase().equals("R")) {
                System.out.println();
                System.out.flush();
                menu();
            }
            else {
                System.out.println("Invalid Input...");
                continue;
            }
        }
    }
    public static int month, day;
    public static int datetodaynumber(int month, int day) {
        int result = 0;
        //Catch Invalid New Scanner
        if (month < 1 || month > 12 || day < 1 || day > 31) {
            result = 0;
        } else if (month == 1) {
            result = day;
        } else if (month == 2) {
            result = day + 31;
        } else if (month == 3) {
            result = day + 59;
        } else if (month == 4) {
            result = day + 90;
        } else if (month == 5) {
            result = day + 120;
        } else if (month == 6) {
            result = day + 151;
        } else if (month == 7) {
            result = day + 181;
        } else if (month == 8) {
            result = day + 212;
        } else if (month == 9) {
            result = day + 243;
        } else if (month == 10) {
            result = day + 273;
        } else if (month == 11) {
            result = day + 304;
        } else if (month == 12) {
            result = day + 334;
        }
        return result;
    }
    public static int daynumber;
    public static int daynumbertomonth(int daynumber){
        /* Catch Invalid New Scanner */
        if (daynumber< 1 || daynumber >365){
            return  0;
        }
        if (daynumber <= 31) {
            return  1;
        }
        if (daynumber <= 59) {
            return  2;
        }
        if (daynumber <= 90) {
            return  3;
        }
        if (daynumber <= 120) {
            return  4;
        }
        if (daynumber <= 151) {
            return  5;
        }
        if (daynumber <= 181) {
            return 6;
        }
        if (daynumber <= 212) {
            return  7;
        }
        if (daynumber <= 243) {
            return  8;
        }
        if (daynumber <= 273) {
            return  9;
        }
        if (daynumber <= 304) {
            return  10;
        }
        if (daynumber <= 334) {
            return  11;
        }
        if (daynumber <= 365) {
            return 12;
        }
        else {
            return 0;
        }
    }
    public static int daynumbertodayofmonth(int daynumber){
        /* Catch Invalid New Scanner */
        if (daynumber < 1 || daynumber > 365){
            return  0;
        }
        if (daynumber <= 31 ){
            return daynumber;
        }
        if (daynumber <= 59) {
            return daynumber - 31;
        }
        if (daynumber <= 90) {
            return daynumber - 59;
        }
        if (daynumber <= 120) {
            return daynumber - 90;
        }
        if (daynumber <= 151) {
            return daynumber - 120;
        }
        if (daynumber <= 181) {
            return daynumber - 151;
        }
        if (daynumber <= 212) {
            return daynumber - 181;
        }
        if (daynumber <= 243) {
            return daynumber - 212;
        }
        if (daynumber <= 273) {
            return daynumber - 243;
        }
        if (daynumber <= 304) {
            return daynumber - 273;
        }
        if (daynumber <= 334) {
            return daynumber - 304;
        }
        if (daynumber <= 365) {
            return daynumber - 334;
        }
        else {
            return 0;
        }
    }
    public static int guestidbook;
    public static void findguest() {
        System.out.println("Please Enter Guest ID: ");
        Scanner sguestidbook = new Scanner(System.in);
        try {
            guestidbook = sguestidbook.nextInt();
            for (int g = 0; g < guestdtl.length; g++) {
                if (guestdtl[guestidbook] != null) {
                    findroom();
                }
            }
            System.out.println("Guest Does Not Exists.\n");
            findguest();
        } catch (Exception e) {
            System.out.println("Please Enter Valid Guest ID.");
            findguest();
        }
    }
    public static int roomNobook, noGuestBook;
    public static void findroom() {
        System.out.println("Please Enter Room Number : ");
        Scanner sroomNobook = new Scanner(System.in);
        try {
            roomNobook = sroomNobook.nextInt();
            for (int i = 0; i < roomdtl.length; i++) {
                Integer s = roomdtl[i][0];
                if (s != null) {
                    if (roomNobook == roomdtl[i][0]) {
                        System.out.println("Please Enter Number of Guests :");
                        Scanner snoGuestBook = new Scanner(System.in);
                        try {
                            noGuestBook = snoGuestBook.nextInt();
                            int cap = roomdtl[i][1];
                            if ((noGuestBook > 0) && (noGuestBook <= cap)) {
                                monthin();
                            } else {
                                System.out.println("Guest(s) count exceeds room capacity of: " + cap + "\n");
                                findroom();
                            }
                        } catch (Exception e) {
                            System.out.println("Please Enter Valid Number of Guest(s).");
                            findroom();
                        }
                    }
                }
            }
            System.out.println("Room Does Not Exists.\n");
            findroom();
        } catch (Exception e) {
            System.out.println("Please Enter Valid room number.");
            findroom();
        }
    }
    public static int inmonth, inday, outmonth, outday, checkinDn, checkoutDn;
    public static void monthin(){
        System.out.println("Please Enter Check-in Month: ");
        Scanner sinmonth = new Scanner(System.in);
        try {
            inmonth = sinmonth.nextInt();
            if (inmonth < 1 || inmonth > 12) {
                System.out.println("Invalid Month.");
                monthin();
            } else {
                dayin();
            }
        } catch (Exception e) {
            System.out.println("Please Enter Valid Check-in Month.");
            monthin();
        }
    }
    public static void dayin() {
        System.out.println("Please Enter Check-in Day: ");
        Scanner sinday = new Scanner(System.in);
        try {
            inday = sinday.nextInt();
            if (inday < 1 || inday > 31) {
                System.out.println("Invalid Day.");
                dayin();
            } else {
                checkinDn = datetodaynumber(inmonth, inday);
                monthout();
            }
        } catch (Exception e) {
            System.out.println("Please Enter Valid Check-in day.");
            dayin();
        }
    }
    public static void monthout() {
        System.out.println("Please Enter Check-out Month: ");
        Scanner soutmonth = new Scanner(System.in);
        try {
            outmonth = soutmonth.nextInt();
            if (outmonth < 1 || outmonth > 12) {
                System.out.println("Invalid Month.");
                monthout();
            } else {
                dayout();
            }
        } catch (Exception f) {
            System.out.println("Please Enter Valid Check-out Month.");
            monthout();
        }
    }
    public static void dayout() {
        System.out.println("Please Enter Check-out Day: ");
        Scanner soutday = new Scanner(System.in);
        try {
            outday = soutday.nextInt();
            if (outday < 1 || outday > 31) {
                System.out.println("Invalid Day.");
                dayout();
            } else {
                checkoutDn = datetodaynumber(outmonth, outday);
                checkdates();
            }
        } catch (Exception nonintegererror) {
            System.out.println("Please Enter Valid Check-out Day.");
            dayout();
        }
    }
    public static void checkdates(){
        for (int i=0; i            Integer s = bookingdtl[i][0];
            if (s != null) {
                int rnb = bookingdtl[i][1];
                int ind = bookingdtl[i][3];
                int outd = bookingdtl[i][4];
                if (roomNobook == rnb) {
                    if ((checkinDn > ind && checkinDn <= outd) || (checkoutDn > ind && checkoutDn <= outd)) {
                        System.out.println("\nRoom is Not Available during that period.");
                        changeroom();
                    }
                    continue;
                }
            }
        }
        setbook();
    }
    public static void changeroom() {
        System.out.println("Please Enter New Room number: ");
        Scanner qroomNobook = new Scanner(System.in);
        try {
            roomNobook = qroomNobook.nextInt();
            for (int i = 0; i < roomdtl.length; i++) {
                Integer s = roomdtl[i][0];
                if (s != null) {
                    if (roomNobook == roomdtl[i][0]) {
                        int cap = roomdtl[i][1];
                        if (noGuestBook > 0 && noGuestBook <= cap) {
                            checkdates();
                        } else {
                      ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here