Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Translate to code in Eclipse Hotel + name : String + Hotel(size: int, name: String) + getNumberOfRooms(): int + addRoom(r: Room): boolean + countRoom(type:String): int

Translate to code in Eclipse

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Hotel + name : String + Hotel(size: int, name: String) + getNumberOfRooms(): int + addRoom(r: Room): boolean + countRoom(type:String): int + count SeniorGuests(): int + getEmpty Rooms(): Room[] + splitRooms(n:int, crowded: Room[], uncrowded: Room[]); void 1 -rooms Room Guest number : int type : String last : int name : String age : int 0..3 - guests + Guest(name:String, age: int) + getName() + getAge() + Room (number: int, type: String) + Room(r: Room) + getNumber() : int + getType(): String + addGuest(g: Guest) : boolean + getNumGuests(): int + findYoungestGuest(): Guest + countGuest(age: int): int Guest class: Attributes: o name: the name of the guest. o age: the age of the guest. Methods: o Guest(name : String, age : int): constructor o getName(): this method returns the name of the guest. o getAge(): this method returns the age of the guest. Room class: Attributes: O number: the room's number. o type: the room's type. Either "VIP" or "Normal. o last: a static variable that has the last room object number. Methods: o Room(type : String): the constructor. It sets number as last +1 then updates last. Maximum number of guests is 3. o Room(r: Room): a copy constructor. o getNumber(): this method returns the number of the room. o getType(): this method returns the type of the room. o addGuest(g: Guest): this method adds a guest g to the room. It returns true if the guest g is successfully added. Otherwise, it returns false. o getNumGuests(): this method returns the number of guests in the room. o find YoungestGuests(): this method returns the youngest guests in the room. o countGuests(age: int): this method returns the number of guests in the room having the age greater or equal to age. Hotel class: Attributes: o name: the name of the hotel. Methods: o Hotel(size : int, name : String): constructor o getNumberOfRooms(): this method returns the number of the rooms in the hotel. o addRoom(r: Room): this method adds a room r to the Hotel. It returns true if the room r is successfully added. Otherwise, it returns false. o countRoom(type:String): this method returns the number of rooms with the type type. o countSenior Guests(): this method returns the number of guests having the age greater or equal to 50. getEmpty Rooms(): this method returns an array of rooms without any guests in them. The array must be full (no empty indexes). It returns null if there are no empty rooms. o splitRooms(n:int, crowded: Room/), uncrowded: Room[]): this method receives two arrays. It inserts the rooms with guests greater than n into the array crowded. It inserts the rooms with guests equal or less than n into the array uncrowded. Question: Translate into Java code the classes Hotel, Room, and Guest. Then, write a main class Main that creates an object of class Hotel. The object should have your name as its name. The size should be 10. Then it should show the following menu: Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter 0: Exit Enter 1: Add a new Room. Ask the user to choose the room type. Choose room type: Enter 1: VIP Enter 2: Normal Show if the room was added successfully or not. Enter 2: Book room to guests. Show a list of empty rooms. If there was no empty rooms, print "There are no empty rooms" Choose a room Enter 1: Room 1, VIP Enter 2: Room 3. Normal Enter 3: Room 4, Normal Ask the user to add guests by typing their names and ages. Then type done when finished. Or stop after 3 guests (the maximum number of guests in a room) Name: Ali Name: Ali Age: 55 Age: 55 Name: Fahad Name: Fahad Age: 14 Age: 14 Name: done Name: Lulu Age: 12 Enter 3: Statistics Show number of VIP rooms and number of Normal rooms. Show number of empty rooms. Show number of crowded rooms (3 guests) and uncrowded rooms (1 or 2 guests). Show the total number of guests. Show number of senior guests. Show the age of the youngest guest. Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 1 Choose room type: Enter 1: VIP Enter 2: Normal ==> 1 The room was added Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter e: Exit ==> 1 Choose room type: Enter 1: VIP Enter 2: Normal ==> 2 The room was added Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 1 Choose room type: Enter 1: VIP Enter 2: Normal ==> 2 The room was added Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit => 1 Choose room type: Enter 1: VIP Enter 2: Normal Invalid selection. Choose 1 or 2 ==> 1 The room was added Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 1 Choose room type: Enter 1: VIP Enter 2: Normal ==> 2 The room was added Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 3 The number of VIP rooms: 2 The number of Normal rooms: 3 The number of Empty rooms: 5 The number of crowded rooms: The number of uncrowded rooms: @ The total number of guests: The total number of guests: The number of senior guests: The age of the youngest guest: Enter 1: Add a new Room Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 2 . Choose a room: Enter 1: Room 1, VIP Enter 2: Room 2, Normal Enter 3: Room 3, Normal Enter 4: Room 4, VIP Enter 5: Room 5, Normal ==> 2 2 Enter guest name: (type done to exit): Ali Enter guest age: 25 Enter guest name: (type done to exit): Fahad Enter guest age: 10 Enter guest name: (type done to exit): done Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 2 Choose a room: Enter 1: Room 1, VIP Enter 2: Room 3. Normal Enter 3: Room 4, VIP Enter 4: Room 5, Normal => 1 Enter guest name: (type done to exit): Khalid Enter guest age: 65 Enter guest name: (type done to exit): done Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 22 Choose a room: Enter 1: Room 3, Normal Enter 2: Room 4, VIP Enter 3: Room 5, Normal ==> 3 Enter guest name: (type done to exit): Nasser Enter guest age: 55 Enter guest name: (type done to exit): Maha Enter guest age: 45 Enter guest name: (type done to exit): Majid Enter guest age: 15 Enter 1: Add a new Room. Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit ==> 3 3 The number of VIP rooms: 2 The number of Normal rooms: 3 The number of Empty rooms: 2 The number of crowded rooms: 1 The number of uncrowded rooms: 2 The total number of guests: 6 The number of senior guests: 2 The age of the youngest guest: @ Enter 1: Add a new Room, Enter 2: Book room to guests. Enter 3: Statistics Enter @: Exit Goodbye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Explain MIG welding .

Answered: 1 week ago

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago