Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

ITECH5403 – Comparative Programming Languages School of Science, Engineering and Information Technology CRICOS Provider No. 00103D Page 1 of 10 ITECH5403 - Assignment 2 – Parallel Implementations Due...

1 answer below »
ITECH5403 – Comparative Programming Languages
School of Science, Engineering and Information Technology
CRICOS Provider No. 00103D Page 1 of 10
ITECH5403 - Assignment 2 – Parallel Implementations
Due Date: 5pm, Friday of Week 11
This assignment will test your skills in programming applications to specification in a number of different
programming languages, and is worth 20% of your non-invigilated (type A) marks for this course.
Assignment Overview

You are tasked with creating a text-based program for storing data on Hotel Room Bookings - however, as this
is a comparative languages course, you will be creating the same application in the following three programming
languages:
• Java,

• Python, and

• Lisp

As you implement the application in each language you should keep notes on:
- The features of the languages used,
- Which features you found useful, and
- Any issues or complications which arose due to the complexity or lack of any language features.
A
ief discussion document based on these programming features for each individual language accompanying
each implementation is required. Finally, a comparative overview of the languages highlighting how they were
suitable or not suitable for the creating this type of application is also required.
It is recommended that the first version of the application you write is in the programming language which is
most familiar to you. This will help you to have a working 'template' for storing room bookings which you can
then translate into the other programming languages.
Program Specification

When the program first launches, there is a menu which allows the user to select one of the following five
options:
1.) Add a guest
2.) Add a room
3.) Add a booking
4.) View bookings
5.) Quit

The functionality of these options is as follows:
ITECH5403 – Comparative Programming Languages
School of Science, Engineering and Information Technology
CRICOS Provider No. 00103D Page 2 of 10

1.) When users add a guest they provide a name which is stored in some manner of a
ay or list. Guests
are assigned a unique ID value where the first guest added is assigned the ID value 1, the second guest
added is assigned the ID value 2 and so on.

2.) When users add a room they provide a room number and a room capacity (i.e. how many people can
stay in the room at any one time) which is stored in some manner of a
ay or list. Rooms have a property
which indicates if they are booked or not for any given date – please see the Room Booking Dates
section below for some guidance on the easiest way to implement this.

3.) When users add a booking they provide a guest ID, room number, the number of guests staying and
finally a check-in date and check-out date.

To successfully create a room booking:

• The guest ID must be a guest which is registered on the system,

• The room number must be of a room that exists,

• The room must be able to accommodate the number of people in the booking (i.e. if the room
capacity is for 2 people and the booking has 4 people staying then the booking must be
efused), and finally

• The room must be available on the dates requested.

4.) When users views bookings they have the option to:
a. View guest bookings, or
. View room bookings.
If the user opts to show guest bookings then they are prompted to enter the guest ID - and then any
ookings made by that guest are displayed including:
- The guest’s name,
- Which room number they booked & number of guests staying, and
- The check-in and check-out dates.
If the user opts to show room bookings then they are prompted to enter a room number - and then any
ookings for that room within the cu
ent year are displayed, including:
- The guest’s name,
- The number of guests staying, and
- The check-in and check-out dates.
5.) When a user chooses to Quit the program terminates with a goodbye message.
Each implementation of your project (in each of the three languages you choose) should aim to closely match
the setup and structure of the program as shown in the example output on the following pages.
ITECH5403 – Comparative Programming Languages
School of Science, Engineering and Information Technology
CRICOS Provider No. 00103D Page 3 of 10
You may wish create separate Guest, Room and potentially Booking classes as part of your implementations,
ut you do not have to.

You may also wish to add code to pre-create a number of guests, rooms and bookings on each run of your code
to avoid the need to type in these details over and over when testing your program. If you do so, please
comment out these pre-defined entries before submitting your assignment.
Room Booking Dates

Dates can be a complex subject to do co
ectly in programming because we often want to calculate how many
days are between dates, and there are issues like date formats (dd/mm/yy? mm/dd/yyyy?) to consider as well
as leap years where Fe
uary has 29 days instead of the usual 28 and so on.

Some programming languages come with built-in classes to work with dates – and you may use them if you
wish. In fact, you are encouraged to use them as they are precisely what you would use when working in the
eal world, so experience in them now will increase your programming knowledge!

However, to keep things simple, our room booking system will only allow bookings within the cu
ent year, and
the easiest way to do that is to store dates as the number of the day between 1 and 365. So, day 18 would be
the 18th of January (which has 31 days), day 32 would be the 1st of Fe
uary, and so on.
As such, one way to keep track of whether a room is booked or not for a cu
ent day would be for each room
to have an a
ay of 365 boolean values which are all set to false (i.e. room is not booked for that particular day)
when the room is first created.
Then, because users don’t like entering dates as values between 1 and 365, we could have four utility methods:

- int dateToDayNumber(int month, int day),
- int dayNumberToMonth(int dayNumber),
- int dayNumberToDayOfMonth(int dayNumber), and
- bool setBooked(int startDayNumber, int endDayNumber).

Example code for the first tree of these methods, written in a Java-like syntax, is provided on the following page – you
should write the setBooked method yourself. The above setBooked method signature assumes you are running the
method on a Room object – if you are not, then you will also have to pass in the room number so you know which
oom’s booked a
ay to modify!
The setBooked method should check if the room is booked for each day between the start and end dates (inclusive) to
ensure the room is available. If the room is not available on a day the method returns false, but if the room is available
etween the start and end dates then it should be set to booked for each day requested and the method should return
true to indicate success.
Bookings are not required to have booking ID values assigned to them, but you may add them if you wish as they may
e useful to later functionality.
ITECH5403 – Comparative Programming Languages
School of Science, Engineering and Information Technology
CRICOS Provider No. 00103D Page 4 of 10
int dateToDayNumber(int month, int day) {

Catch invalid input and return early
if (month < 1 || month > 12 || day < 1 || day > 31) return 0;

if (month == 1 ) return day;
if (month == 2 ) return 31 + day;
if (month == 3 ) return 59 + day;
if (month == 4 ) return 90 + day;
if (month == 5 ) return 120 + day;
if (month == 6 ) return 151 + day;
if (month == 7 ) return 181 + day;
if (month == 8 ) return 212 + day;
if (month == 9 ) return 243 + day;
if (month == 10) return 273 + day;
if (month == 11) return 304 + day;
return 334 + day;
}

int dayNumberToMonth(int dayNumber) {

Catch invalid input and return early
if (dayNumber < 1 || dayNumber > 365) return 0;

if (dayNumber <= 31 ) return 1;
Jan
if (dayNumber <= 59 ) return 2;
Feb
if (dayNumber <= 90 ) return 3;
Mar
if (dayNumber <= 120) return 4;
Apr
if (dayNumber <= 151) return 5;
May
if (dayNumber <= 181) return 6;
Jun
if (dayNumber <= 212) return 7;
Jul
if (dayNumber <= 243) return 8;
Aug
if (dayNumber <= 273) return 9;
Sep
if (dayNumber <= 304) return 10;
Oct
if (dayNumber <= 334) return 11;
Nov
eturn 12;
Dec
}

int dayNumberToDayOfMonth(int dayNumber) {

Catch invalid input and return early
if (dayNumber < 1 || dayNumber > 365) return 0;

if (dayNumber <= 31 ) return dayNumber;
Jan
if (dayNumber <= 59 ) return dayNumber - 31;
Feb
if (dayNumber <= 90 ) return dayNumber - 59;
Mar
if (dayNumber <= 120) return dayNumber - 90;
Apr
if (dayNumber <= 151) return dayNumber - 120;
May
if (dayNumber <= 181) return dayNumber - 151;
Jun
if (dayNumber <= 212) return dayNumber - 181;
Jul
if (dayNumber <= 243) return dayNumber - 212;
Aug
if (dayNumber <= 273) return dayNumber - 243;
Sep
Answered Same Day May 27, 2021 ITECH5403

Solution

Neha answered on May 31 2021
144 Votes
59050/Hotel.java
59050/Hotel.java
package com.company;
import java.util.Scanner;
public abstract class Hotel{
    public static String[] creds1 = new String[1000];
    public static Integer[][] creds2 = new Integer[1000][2];
    public static Integer[][] creds3 = new Integer[1000][5];
    public static void main(String[] args){
        main1();
    }
    public static void main1() {
        String a = "****************************************"
                + "****************************************";
        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() {
        
 Initializing A
ay Data For testing Program.
        creds1[0] = "NULL";
        creds1[1] = "Sara Williams";
        creds1[2] = "David THomson";
        creds1[3] = "Monica Silva";
        creds2[0][0] = 4001;
        creds2[0][1] = 2;
        creds2[1][0] = 4002;
        creds2[1][1] = 3;
        creds2[2][0] = 4003;
        creds2[2][1] = 5;
        creds2[3][0] = 4004;
        creds2[3][1] = 1;
        creds2[4][0] = 4005;
        creds2[4][1] = 2;
        creds3[0][0] = 1;
        creds3[0][1] = 4001;
        creds3[0][2] = 2;
        creds3[0][3] = 260;
        creds3[0][4] = 264;
        creds3[1][0] = 2;
        creds3[1][1] = 4005;
        creds3[1][2] = 3;
        creds3[1][3] = 210;
        creds3[1][4] = 212;
        creds3[2][0] = 1;
        creds3[2][1] = 4003;
        creds3[2][2] = 5;
        creds3[2][3] = 160;
        creds3[2][4] = 164;
        creds3[3][0] = 3;
        creds3[3][1] = 4004;
        creds3[3][2] = 1;
        creds3[3][3] = 110;
        creds3[3][4] = 114;
        creds3[4][0] = 3;
        creds3[4][1] = 4001;
        creds3[4][2] = 1;
        creds3[4][3] = 150;
        creds3[4][4] = 154;
    }
    public static void start() {
        System.out.println("Please make a choice : ");
        Scanner answer = new Scanner(System.in);
        try {
            int input = answer.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("Thank You.....");
                System.Exit();
            } else {
                System.out.println("\nPlease make a valid choice");
                start();
            }
        } catch (Exception e) {
            System.out.println("Please make a valid choice....");
            start();
        }
    }
    public static void addroom() {
        System.out.println("Enter Room Number -");
        Scanner irno = new Scanner(System.in);
        try {
            int rno = irno.nextInt();
            System.out.println("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 < creds2.length; r++) {
                        Integer s = creds2[r][0];
                        if (s != null) {
                            int rn = creds2[r][0];
                            if (rno == rn) {
                                System.out.println("\nSame Room Already Exists.");
                                addroom();
                            }
                        }
                    }
                    int i = 0;
                    for (int i1 = 0; i1 < creds2.length; i1++) {
                        Integer s = creds2[i1][0];
                        if (s != null) {
                            i++;
                        }
                    }
                    creds2[i][0] = rno;
                    creds2[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("\nEnter A to add another room or R to return to 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();
                main1();
            }
            else {
                System.out.println("Invalid Input...");
                continue;
            }
        }
    }
    public static void addguest() {
        System.out.println("Enter Guest Name below -");
        System.out.println("First Name: ");
        Scanner namef = new Scanner(System.in);
        String fname = namef.nextLine();
        System.out.println("Last Name: ");
        Scanner namel = new Scanner(System.in);
        String lname = namel.nextLine();
        if((fname.equals("")) || (lname.equals(""))){
            System.out.println("Invalid Name\n");
            System.out.println("Please Enter Valid Name.\n");
            addguest();
        }
        else {
            int i = 0;
            for (int i1 = 0; i1 < creds1.length; i1++) {
                String s = creds1[i1];
                if (s != null) {
                    i++;
                }
            }
            System.out.println("Guest " + fname.toUpperCase() + " " + lname.toUpperCase() + " has been created with Guest ID: " + i);
            creds1[i] = fname.toUpperCase() + " " + lname.toUpperCase();
        }
        while (true){
            System.out.println("\nEnter A to add another guest details or R to return to main 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();
                main1();
            }
            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 Scanne
        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){
        if (daynumbe
 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){
        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 gidbook;
    public static void findguest() {
        System.out.println("Please Enter Guest ID: ");
        Scanner sgidbook = new Scanner(System.in);
        try {
            gidbook = sgidbook.nextInt();
            for (int g = 0; g < creds1.length; g++) {
                if (creds1[gidbook] != 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 rnobook, nogbook;
    public static void findroom() {
        System.out.println("Enter Room Number : ");
        Scanner srnobook = new Scanner(System.in);
        try {
            rnobook = srnobook.nextInt();
            for (int i = 0; i < creds2.length; i++) {
                Integer s = creds2[i][0];
                if (s != null) {
                    if (rnobook == creds2[i][0]) {
                        System.out.println("Enter Number of Guests :");
                        Scanner snogbook = new Scanner(System.in);
                        try {
                            nogbook = snogbook.nextInt();
                            int cap = creds2[i][1];
                            if ((nogbook > 0) && (nogbook <= 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, indn, outdn;
    public static void monthin(){
        System.out.println("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("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 {
                indn = datetodaynumber(inmonth, inday);
                monthout();
            }
        } catch (Exception e) {
            System.out.println("Please Enter Valid Check-in day.");
            dayin();
        }
    }
    public static void monthout() {
        System.out.println("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("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 {
                outdn = datetodaynumber(outmonth, outday);
                checkdates();
            }
        } catch (Exception nonintegere
or) {
            System.out.println("Please Enter Valid Check-out Day.");
            dayout();
        }
    }
    public static void checkdates(){
        for (int i=0; i            Integer s = creds3[i][0];
            if (s != null) {
                int rnb = creds3[i][1];
                int ind = creds3[i][3];
                int outd = creds3[i][4];
                if (rnobook == rnb) {
                    if ((indn > ind && indn <= outd) || (outdn > ind && outdn <= outd)) {
                        System.out.println("\nNo rooms available.");
                        changeroom();
                    }
                    continue;
                }
            }
        }
        setbook();
    }
    public static void changeroom() {
        System.out.println("Please Enter New Room number: ");
        Scanner qrnobook = new Scanner(System.in);
        try {
            rnobook = qrnobook.nextInt();
            for (int i = 0; i < creds2.length; i++) {
                Int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here