5
\$\begingroup\$

The code below runs perfectly fine as I want it to. I'd like to create more subclasses to get a better overview over the whole code. Can I place the setter and getter as well as the methods into the extended classes? I'd like to create subclasses as in 'single room', 'double room' etc., to extend room. Would it improve my code? My prof wants to see more classes.

By the way, the code comments are in German, so if there are any questions, I'm happy help.

To simplify my question, the option pet is just available for Penthouse. Does it make sense to create a subclass for Penthouse to move to setter and getter to the subclass?

import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Scanner;

public class Booking {
    private static boolean CustomerInterface = true;//Hauptprogramm boolean

    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(System.in);

        Room[] hotel = new Room[8];//Array für Zimmer

        hotel[0] = new Room(40, true, 1);//Single room
        hotel[1] = new Room(40, true, 2);//Single room
        hotel[2] = new Room(70, true, 3);//Double room
        hotel[3] = new Room(70, true, 4);//Double room
        hotel[4] = new Room(100, true, 5);//Triple room
        hotel[5] = new Room(100, true, 6);//Triple room
        hotel[6] = new Penthouse(200, true, 7, false);//Penthouse
        hotel[7] = new Penthouse(200, true, 8, false);//Penthouse

        System.out.println("Willkommen im Hotel AppDev1");//Begrüßung

        while (CustomerInterface) {//Abfrage des Boolean zum Start des Hauptprogramms
            System.out.println("Bitte wählen sie eine der folgenden Auswahlmöglichkeiten:");
            System.out.println("********************************************************");
            System.out.println("1: Buchen sie einen Raum\n2: List der verfügbaren Zimmer anzeigen" +
                    "\n3: Liste aller Zimmer anzeigen\n4: Kunde auschecken\n5: Gäste Anzeigen\n6: Program ende");
            System.out.println("********************************************************");

            String Selection = input.next();
            switch (Selection) {
                case "1":
                    Booking(hotel);//Methode zum Buchen
                    break;
                case "2":
                    ShowEmpty(hotel);//Freie Zimmer anzeigen
                    break;
                case "3":
                    ShowAll(hotel);//Alle Zimmer anzeigen
                    break;
                case "4":
                    DeleteCustomer(hotel);//Kundendaten je Zimmernummer löschen
                    break;
                case "5":
                    Gastdaten(hotel);//Gästedaten:Name, Preise, Buchungsoptionen anzeigen
                    break;
                case "6":
                    ShutDown();//Programm beenden
                    break;
                default:
                    WrongInput();//Flasche Eingabe getätigt
                    CustomerInterface = true;//Hauptprogramm neu starten
            }
        }
    }

    private static void PreisKategorie(Room []hotel, int roomNr) {//Auswahl der Zimmerkategorie von Standart bis Luxus
        System.out.println("Welche Preiskategorie möchten sie?\n1 = Standard\n2 = Premium (10% Zuschlag)\n 3 = Luxus (20% Zuschlag)");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch(userInput) {
            case "1":
                System.out.println("Sie haben Standard gewählt. ");
                hotel[roomNr].setPriceLevel(1.0);//Standartpreis
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() * hotel[roomNr].getPriceLevel());
                break;
            case "2":
                System.out.println("Sie haben Premium gewählt. ");
                hotel[roomNr].setPriceLevel(1.1);//10% Premiumzuschlag
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() * hotel[roomNr].getPriceLevel());
                break;
            case "3":
                System.out.println("Sie haben Luxus gewählt. ");
                hotel[roomNr].setPriceLevel(1.2);//20% Luxuszuschlag
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() * hotel[roomNr].getPriceLevel());
                break;
            default:
                WrongInput();//Falsche Eingabe
                PreisKategorie(hotel, roomNr);//Zurück zum Beginn der Kategorieauswahl
        }

    }

    private static void ShutDown() {//Programm beenden
        System.out.println("Danke, auf wiedersehen.");
        System.exit(0);
    }

    private static void Booking(Room[] hotel) {//Zimmer buchen
        
                String userInput;
                Scanner input = new Scanner(System.in);
                System.out.println("Bitte geben sie eine der folgenden Zimmernummern ein:\n1-2 Einzelzimmer, Preis für eine" +
                        " Übernachtung = " + " " + "\n3-4 Doppelzimmer" +
                        "\n5-6 Drreibettzimmer\n7-8 Ferienwohnug\n9 Programm beenden");
                userInput = input.next();

                switch (userInput) {
                    case "1":
                        if (hotel[0].getAvailable(hotel[0].available)) {
                            System.out.println(hotel[0].getPricePerNight());
                            int roomNr = 0;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            System.out.println(hotel[0].getPricePerNight());
                            Balcony(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "2":
                        if (hotel[1].getAvailable(hotel[1].available)) {
                            int roomNr = 1;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            Balcony(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);

                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "3":
                        if (hotel[2].getAvailable(hotel[2].available)) {
                            int roomNr = 2;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            Balcony(hotel, roomNr);
                            SinglePerson(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "4":
                        if (hotel[3].getAvailable(hotel[3].available)) {
                            int roomNr = 3;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            Balcony(hotel, roomNr);
                            SinglePerson(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "5":
                        if (hotel[4].getAvailable(hotel[4].available)) {
                            int roomNr = 4;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            SecondToilet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "6":
                        if (hotel[5].getAvailable(hotel[5].available)) {
                            int roomNr = 5;
                            PreisKategorie(hotel, roomNr);
                            Breakfast(hotel, roomNr);
                            SecondToilet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "7":
                        if (hotel[6].getAvailable(hotel[6].available)) {
                            int roomNr = 6;
                            PreisKategorie(hotel, roomNr);
                            CountGuests(hotel, roomNr);
                            Pet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            RoomService(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "8":
                        if (hotel[7].getAvailable(hotel[7].available)) {
                            int roomNr = 7;
                            PreisKategorie(hotel, roomNr);
                            CountGuests(hotel, roomNr);
                            Pet(hotel, roomNr);
                            BookingPeriode(hotel, roomNr);
                            RoomService(hotel, roomNr);
                            FinalizeBooking(hotel, roomNr);
                        } else {
                            AldreadyBooked(hotel);
                        }
                        break;
                    case "9":
                        ShutDown();
                        break;
                    default:
                        WrongInput();
                        Booking(hotel);
                }

                //int roomNr;
                //roomNr = Integer.valueOf(userInput) - 1;//wandelt die eingabe in int um und -1 damit Zimmer 1 = room[0]
                //FinalizeBooking(hotel, roomNr);



    }

    private static void FinalizeBooking(Room @NotNull [] hotel, int roomNr) {
        String userInput;
        Scanner input = new Scanner(System.in);
        String rName;
        System.out.println("Bitte geben sie ihren Namen ein : ");
        rName = input.next();//Kundenname für die Buchung
        //rName = String.valueOf(roomNr);//wandelt rName in int um es der arry zuzuodrnen
        //Option 1 mit boolean
        hotel[roomNr].setAvailable(false);
        //Option 2 mit equals
        hotel[roomNr].setName(rName);//hinterlegt in der arry den Namen des Gastes
        Receipt(hotel, roomNr);

    }

    private static void Receipt(Room @NotNull [] hotel, int roomNr) {
        System.out.println("Danke für ihre Buchung, das Zimmer" + " " + (roomNr + 1) + " " +
                "ist für sie reserviert\nDie Gesamtsumme beträgt: " + (hotel[roomNr].getPricePerNight() * 1.19) + "€" +
                "\n Die enthaltende Mehrwertsteuer beträgt: " +(hotel[roomNr].getPricePerNight() * 0.19));
        if ((hotel[roomNr].getFrühstück()==true) || (hotel[roomNr].getBalkon()==true) || (hotel[roomNr].getSinglePerson()==true) || (hotel[roomNr].getGästetoilette()==true) || (hotel[roomNr].getPet()==true) || (hotel[roomNr].getRoomService()==true)) {
            System.out.println("Sie haben die folgenden optionen mit gebucht:");
            if (hotel[roomNr].getFrühstück() == true) {
                System.out.println("Frühstück: " + hotel[roomNr].getBreaky() * hotel[roomNr].getBookingPeriode() + "€");
            }

            if (hotel[roomNr].getBalkon() == true) {
                System.out.println("Balkon: " + hotel[roomNr].getBalcony() * hotel[roomNr].getBookingPeriode() + "€");
            }

            if (hotel[roomNr].getSinglePerson() == true) {
                System.out.println("Einzelpersonrabatt: " + hotel[roomNr].getEinzelPerson() * hotel[roomNr].getBookingPeriode() + "€");
            }

            if (hotel[roomNr].getGästetoilette() == true) {
                System.out.println("Gäste Toilette: " + hotel[roomNr].getSecondToilet() * hotel[roomNr].getBookingPeriode() + "€");
            }

            if (hotel[roomNr].getPet() == true) {
                System.out.println("Haustierzuschlag: " + hotel[roomNr].getHaustier() * hotel[roomNr].getBookingPeriode() + "€");
            }
            if (hotel[roomNr].getRoomService() == true) {
                System.out.println("Zimmerservie: " + hotel[roomNr].getZimmerservice() * hotel[roomNr].getBookingPeriode() + "€");
            }
        } else {
            System.out.println("Sie haben keine Zusatzoptionen gebucht");
        }
    }

    private static void RoomService(Room[] hotel, int roomNr) {
        System.out.println("Möchten sie Zimmerservice dazubuchen? \n" +" 1 = ja 2= Nein");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput){
            case "1":
                System.out.println("Sie haben inklusive Zimmerservice gebucht");
                hotel[roomNr].setRoomService(true);
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() + Room.getZimmerservice());
                break;
            case "2":
                System.out.println("Sie haben ohne Zimmerservice gebucht");
                hotel[roomNr].setRoomService(false);
                break;
            default: WrongInput();
            RoomService(hotel, roomNr);
        }
    }

    private static void AldreadyBooked(Room[] hotel) {
        System.out.println("Dieses Zimmer ist leider schon belegt\n Bitte wählen sie ein anders Zimmer.");
        //CustomerInterface = true;
        Booking(hotel);
    }

    private static void WrongInput() {
        System.out.println("********************************************************");
        System.out.println("Ihre eingabe war leider nicht Korrekt.\nBitte versuchen sie es erneut.");
        System.out.println("********************************************************");
    }

    private static void Pet(Room[] hotel, int roomNr) {
        System.out.println("Kommen Sie mit oder ohne Haustier\n1 = mit \n2 = ohne");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie nehmen ein Haustier mit");
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() + hotel[roomNr].getHaustier());//3 € Aufpreis für ein Haustier
                hotel[roomNr].pet = true;
                break;
            case "2":
                System.out.println("sie nehmen kein Haustier mit");
                hotel[roomNr].pet = false;
                break;
            default:
                WrongInput();
                Pet(hotel, roomNr);
                break;
        }
    }

    private static void BookingPeriode(Room[] hotel, int roomNr) {
        if (roomNr < 7){
            System.out.println("Wie lange bleiben Sie? ");
            Scanner input = new Scanner(System.in);
            String userInput;
            userInput = input.next();
            switch (userInput) {
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                case "10":
                case "11":
                case "12":
                case "13":
                case "14":
                    System.out.println("sie haben" + " " + userInput + " " + "Tage gewählt");
                    hotel[roomNr].setBookinperiode(Integer.valueOf(userInput));
                    hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() * Integer.valueOf(userInput));

                    break;
                default:
                    WrongInput();
                    BookingPeriode(hotel, roomNr);}

        } else{
            System.out.println("Wie lange bleiben Sie? (Die Mindestbuchungsdauer beträgt 3 Tage\nDie maximale Buchungsdauer beträt 14 Tage)");
            Scanner input = new Scanner(System.in);
            String userInput;
            userInput = input.next();


            switch (userInput) {
                case "1":
                case "2":
                    MinBooking(hotel, roomNr);
                    break;
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                case "10":
                case "11":
                case "12":
                case "13":
                case "14":
                    System.out.println("sie haben" + " " + userInput + " " + "Tage gewählt");
                    hotel[roomNr].setBookinperiode(Integer.valueOf(userInput));
                    hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() * Integer.valueOf(userInput));
                    break;
                default:
                    WrongInput();
                    BookingPeriode(hotel, roomNr);
            }
        }
    }

    private static void MinBooking(Room[] hotel, int roomNr) {
        System.out.println("Sie unterschreiten die Mindestbuchungsdauer! \nMöchten Sie erneut wählen? 1 = neuwahl 2= Programm beenden");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        if (userInput.equals("1")) {
            BookingPeriode(hotel, roomNr);
        } else if (userInput.equals("2")) {
            ShutDown();
        } else {
            WrongInput();
            MinBooking(hotel, roomNr);
        }
    }

    private static void CountGuests(Room[] hotel, int roomNr) {
        System.out.println("Mit wie vielen Personen möchten sie buchen?\nDie maximale Anzahl beträt 6 Personen.)");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
            case "2":
            case "3":
            case "4":
            case "5":
            case "6":
                System.out.println("sie haben" + " " + userInput + " Personen gewählt");
                hotel[roomNr].setCountGuests(Integer.valueOf(userInput));
                break;
            default:
                WrongInput();
                CountGuests(hotel, roomNr);
        }
    }

    private static void SecondToilet(Room[] hotel, int roomNr) {
        System.out.println("Möchten sie ein Zimmer mit Gäste Toilette? 1 = ohne Gäste Toilette 2 = 2 mit Gäste Toilette");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben ein Zimmer ohne Gäste Toilette gewählt");
                hotel[roomNr].gästetoilette = false;


                break;
            case "2":
                System.out.println("sie haben ein Zimmer mit Gäste Toilette gewählt");
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() + Room.getSecondToilet());//10 € Aufpreis für eine extra Toilette
                hotel[roomNr].gästetoilette = true;

                break;
            default:
                WrongInput();
                SecondToilet(hotel, roomNr);
        }
    }

    private static void SinglePerson(Room[] hotel, int roomNr) {
        System.out.println("Bitte geben sie an um wie viele Personen es sich bei ihrer Buchung handelt\n1 = Einzelperson 2= Paar");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben Einzelperson gewählt");
                System.out.println("Sie bekommen einen Sondertarif (10 Euro weniger)");

                hotel[roomNr].singlePerson = true;
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() - hotel[roomNr].getEinzelPerson());
                System.out.println(hotel[roomNr].getPricePerNight());
                break;
            case "2":
                System.out.println("sie haben die Paaroption gewählt");
                hotel[roomNr].singlePerson = false;
                //System.out.println(hotel[roomNr].getPricePerNight());
                break;
            default:
                WrongInput();
                SinglePerson(hotel, roomNr);
        }
    }

    private static void Balcony(Room[] hotel, int roomNr) {
        System.out.println("Möchten sie ein Zimmer mit Balkon buchen? 1 = mit Balkon 2= ohne Balkon");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben ein Zimmer mit Balkon gewählt");
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() + Room.getBalcony());//5 € Aufpreis für einen Balkon
                hotel[roomNr].balkon = true;

                break;
            case "2":
                System.out.println("sie haben ein Zimmer ohne Balkon gewählt");
                hotel[roomNr].balkon = false;
                break;
            default:
                WrongInput();
                Balcony(hotel, roomNr);
        }
    }

    private static void Breakfast(Room @NotNull [] hotel, int roomNr) {
        System.out.println("Möchten sie Frühstück dazu buchen? 1 = mit Frühstück 2= ohne Frühstück");
        Scanner input = new Scanner(System.in);
        String userInput;
        userInput = input.next();
        switch (userInput) {
            case "1":
                System.out.println("sie haben ein Zimmer mit Frühstück gewählt");
                hotel[roomNr].setPricePerNight(hotel[roomNr].getPricePerNight() + Room.getBreaky());//3 € Aufprreis für Frühstück
                hotel[roomNr].frühstück = true;
                //System.out.println(hotel[roomNr].getPricePerNight());
                break;
            case "2":
                System.out.println("sie haben ein Zimmer ohne Frühstück gewählt");
                hotel[roomNr].frühstück = false;
                break;
            default:
                WrongInput();
                Breakfast(hotel, roomNr);
                break;
        }
    }

    private static void ShowEmpty(Room @NotNull [] hotel) {
        for (int i = 0; i < hotel.length; i++) {
            if (hotel[i].getAvailable(hotel[i].available)) {
                System.out.println("Zimmer " + (i + 1) + " steht zur Verfügung");
            }else {
                System.out.println("Zimmer " + (i + 1) + " ist belegt");
            }
        }
    }

    private static void ShowAll(Room @NotNull [] hotel) {
        for (int i = 0; i < hotel.length; i++) {
            System.out.println("Wir bieten Zimmer " + (i + 1) + " an. ");
        }
    }

    private static void DeleteCustomer(Room @NotNull [] hotel) {
        Scanner input = new Scanner(System.in);
        int roomNr;
        System.out.println("Bitte geben sie die Zimmernummer ein");
        roomNr = input.nextInt() - 1;
        hotel[roomNr].setName("Name");
        hotel[roomNr].setAvailable(true);
        System.out.println("Eintrag gelöscht");
    }

    private static void Gastdaten(Room @NotNull [] hotel) {
        for (int i = 0; i < hotel.length; i++) {
            if (hotel[i].getAvailable(!(hotel[i].available))) {

                System.out.println("Es befinden sich zur Zeit Gäste in Zimmer: " + hotel[i].roomNr +
                        "\nName: " + hotel[i].getName() + "\nGesamtpreis ohne MwST: "
                        + hotel[i].getPricePerNight());
                switch (hotel[i].getRoomNr()) {
                    case 1:
                    case 2:
                        System.out.println("Frühstück: " + hotel[i].getFrühstück() + "\nBalkon: " + hotel[i].getBalkon() +
                                "\nDauer des Aufenthalts:" + hotel[i].getBookingPeriode() + "\n");
                        break;
                    case 3:
                    case 4:
                        System.out.println("Frühstück: " + hotel[i].getFrühstück() + "\nBalkon: " + hotel[i].getBalkon() + "\n"
                                + "Einzelpersonenrabatt:" + hotel[i].getSinglePerson() + "\nDauer des Aufenthalts:" + hotel[i].getBookingPeriode() + "\n");
                        break;
                    case 5:
                    case 6:
                        System.out.println("Frühstück: " + hotel[i].getFrühstück() + "\nBalkon: " + hotel[i].getBalkon() + "\n"
                                + "Gäste Toilette:" + hotel[i].getGästetoilette() + "\nDauer des Aufenthalts:" + hotel[i].getBookingPeriode() + "\n");
                        break;
                    case 7:
                    case 8:
                        System.out.println("Anzahl der Gäste: " + hotel[i].getCountGuests() + "\nHaustier: " + hotel[i].getPet() + "\n"
                                + "Zimmerservice: " + hotel[i].getRoomService() + "\nDauer des Aufenthalts:" + hotel[i].getBookingPeriode() + "\n");
                        break;
                }
            } else {
                System.out.println("Es befinden sich zur Zeit keine Gäste in Zimmer: " + " " + hotel[i].getRoomNr() + "\n");
            }
        }
    }
}
package Hotel;

public class Room {



    //String CustomerName;
    private String Name;
    int roomNr;
    double pricePerNight;
    boolean available; //= true;//Zimmer frei oder belegt?
    static double breaky = 3;
    static double balcony = 5;
    boolean frühstück;
    boolean balkon;
    boolean singlePerson;
    boolean gästetoilette;
    static double secondToilet = 10;
    int countGuests;
    boolean pet;
    int bookinperiode;
    boolean roomservice;
    static double zimmerservice = 10;
    static double einzelPerson = 10;
    double haustier = 3;
    static double priceLevel;



    //Constructor
    public Room(double pricePerNight, boolean available,int roomNr) {
        this.pricePerNight = pricePerNight;
        this.available = available;
        this.roomNr = roomNr;
    }

    public boolean getPet() {
        return pet;
    }
    public double getHaustier() {
        return haustier;
    }

    public boolean getRoomService() {
        return roomservice;
    }
    public void setRoomService(boolean roomservice) {
        this.roomservice = roomservice;
    }
    public static double getZimmerservice() {
        return zimmerservice;
    }

    public boolean getGästetoilette() {
        return gästetoilette;
    }
    public static double getSecondToilet() {
        return secondToilet;
    }

    public void setCountGuests(int countGuests) {
        this.countGuests = countGuests;
    }
    public int getCountGuests() {
        return countGuests;
    }

    public boolean getSinglePerson() {
        return singlePerson;
    }
    public double getEinzelPerson() {
        return einzelPerson;
    }

    public boolean getBalkon() {
        return balkon;
    }
    public static double getBalcony() {
        return balcony;
    }

    public boolean getFrühstück() {
        return frühstück;
    }
    public static double getBreaky() {
        return breaky;
    }

    public void setPricePerNight(double pricePerNight) {
        this.pricePerNight = pricePerNight;
    }
    public double getPricePerNight() {
        return pricePerNight;
    }

    public void setBookinperiode(int bookinperiode) {
        this.bookinperiode = bookinperiode;
    }
    public int getBookingPeriode() {
        return bookinperiode;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }
    public boolean getAvailable(boolean available) {
        return available;
    }

    public String getName() {
        return Name;
    }
    public void setName(String Name) {
        this.Name = Name;
    }

    public double getPriceLevel() {
        return priceLevel;
    }
    public void setPriceLevel(double priceLevel) {
        this.priceLevel = priceLevel;
    }

    public int getRoomNr() {
        return roomNr;
    }
}
\$\endgroup\$
3
  • 4
    \$\begingroup\$ "My prof wants to see more classes." I agree. Your Room class contains everything but a kitchen sink (American euphemism). I don't speak German, so I cant show you, but I saw Customer, Booking, and Room classes all mixed in one Room class. (A customer books a room). Basically, every noun in the problem description is a potential class object. \$\endgroup\$ – Gilbert Le Blanc Jul 1 '20 at 13:57
  • 1
    \$\begingroup\$ Also, separate your static and non-static class variables. Separate your class variables by data type. It makes the class easier for a person to understand. \$\endgroup\$ – Gilbert Le Blanc Jul 1 '20 at 14:03
  • \$\begingroup\$ I'd guess most of the review hints in the answers could be sorted out by using a propert IDE. While it may slow down some learnings, it really helps in generating boilerplate properly, hinting typos, avoiding duplicates, etc. \$\endgroup\$ – Clijsters Jul 3 '20 at 8:25
4
\$\begingroup\$

OOAD - Object Orientated Analyze and Design

It's always a good idea to start with a pen and a pencil before you do any coding. Here is a demonstration on how such an Design could look like (I strongly recommend UML since this kind of diagramms is understood by everybody among engineers)

enter image description here

Honestly I do not fully understand your requirements (your homework task), so this design maybe a flawed. Take it and adjust it to your needs.

Pets

Since bringing pets to your room is not depending on any room feature (the hotel management might allow as an exception to bring your pet to a regular room) this feature is only a pricing feature. Having a design in your hands now, you can easily decide, where to put such extra-chargings into: the Booking! this is also where your breakfast should be.

Helpful hints

\$\endgroup\$
3
\$\begingroup\$
  • Question: method and normal variable names in java start with a small letter by convention. As opposed to C#. Is it a special convention of the course?
  • Repetitive code for array entries.
  • X == true is simply X and X == false is !X (not X).
  • Parameters f(X[] array, int index) might just be f(X x). It also might be that then the called method should be a method of X.f(). Call: f(array[index]). (You can change fields of the X inside f.)
  • double haustier (pet) would make me shiver, like double children - int?

Now to the question:

  • Subclasses of Room: Penthouse, Besenkammer, ... to be placed in a Room array will probably not be very manageable.
  • But you have many features of a room and instead of many fields you could have a RoomProperty and derive subclasses like HavingPet (or whatever) and call overriden ask(), String toString(), additionalPrice() and so on. That would make sense. And then use a RoomProperty[] properties = new RoomProperties[10];. Instead of fixed size arrays you will later learn dynamic, growing List (i.e. ArrayList).
  • A penthouse could then be realized by a Room subclass that fills its initial properties with a HavingPet.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ double haustier (pet) would make me shiver - very nice!!!! \$\endgroup\$ – Martin Frank Jul 3 '20 at 7:16
3
\$\begingroup\$

Naming

Naming is really important. There are conventions that help to give helpful hints to the reader about what a name refers to. camelCase names on their own are typically going to be variables, camelCase( with parenthesis are likely to be function calls. Capitals are typically used for classes, constants, enums.

So, when I see something like this:

Booking(hotel);//Methode zum Buchen

It takes more processing to figure out what Booking is referring to, because it looks like a constructor call. This is reinforced by the name itself Booking sounds like a thing, rather than an action, so I'm expecting it to be a class name. If you need to add a comment to tell you it's the booking method, then it's probably a good sign that the name could be improved... createBooking might be a more descriptive name.

Don't cheat with your names...

boolean roomservice;
static double zimmerservice = 10;

I'd suggest picking a single language for your actual code, commenting in a different language is fine, however if you use both languages for the code then you can get into situations like the one above where you basically have the same name, meaning two different things. This is confusing. One of these should really have a different name. roomServiceCost perhaps?

Money...

People are funny about losing money to rounding errors... Generally when you're dealing with Money you want to consider using BigDecimal, rather than double. It is a bit harder to work with than double though and for this application may not be necessary.

Customer Interface?

private static boolean CustomerInterface = true;//Hauptprogramm boolean

It's really unclear what this variable is for. It seems like it's possibly supposed to be used to determine if the interface is displayed, however it's always set to true...

Duplication

Look out for duplication in your code. It's a good sign that there may be other abstractions, either methods or classes. So, in your Booking method, you're doing more or less the same thing in each of the case's

       case "2":
           if (hotel[1].getAvailable(hotel[1].available)) {
               int roomNr = 1;
               PreisKategorie(hotel, roomNr);
               Breakfast(hotel, roomNr);
               Balcony(hotel, roomNr);
               BookingPeriode(hotel, roomNr);
               FinalizeBooking(hotel, roomNr);

Consider if there's a way to convert the userInput into a number that can be used to drive this booking experience and remove some of this redundancy.

Call Depth

Be careful about call circles. So, your Booking method, can call AldreadyBooked, which in turn calls back to Booking. Each method call adds to the call stack. If this happens enough times, then you're running the risk of a stack overflow. Rather than following this circle, consider if there's a way to pass indicate success/failure back up to the caller so that it can make a decision about what to do next, rather than calling back out to the caller like this.

Booking vs Room vs Request

The most obvious first step for a split in your data is to consider what are attributes of a Room and what are attributes of a booking.

A Room has certain attributes that aren't related to a booking, they're just a part of the room. That might be things like roomNumber, beds, toilets, allowsPets etc.

A RoomBooking on the other hand might consist of things related to a specific booking, so things like bookedRoom, price, breakfastRequired etc.

You then might have another abstraction, such as BookingRequest, which would have things like numberPeople, breakfastRequired, fromDate, numberNights etc, which could be used to determine which rooms would satisfy the customer and which are available.

Having these sorts of abstractions makes it easier to think about how to rework the logic to add extra functionality... so, for example if the customer only needs to have room for a single, but all of the rooms with a single bed are reserved, then you could offer them a double room instead.

Visibility

Your Room class has one private member and a lot of internal ones. Consider if this really makes sense...

Statics

If you're going to have statics in your class, it's a good idea to group them together, rather than sprinkling them amongst the other variables.

If your statics are supposed to be constant, which I think a lot of yours are, you should mark them as final to indicate that they're not going to change.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.