Knowee
Questions
Features
Study Tools

Create a class called “HotelRoom” that includes an integer field for the room number and a double field for the nightly rental rate. Include get methods for these fields and a constructor that requires an integer argument representing the room number. The constructor sets the room rate based on the room number; rooms numbered 100 and below are Rs 500 per night, others are Rs.800 per night.Create an extended class name Suite whose constructor requires a room number and adds a Rs 400 surcharge to the regular hotel room rate based on the room number. Write a program to demonstrate creating and using an object of each class.

Question

Create a class called “HotelRoom” that includes an integer field for the room number and a double field for the nightly rental rate. Include get methods for these fields and a constructor that requires an integer argument representing the room number. The constructor sets the room rate based on the room number; rooms numbered 100 and below are Rs 500 per night, others are Rs.800 per night.Create an extended class name Suite whose constructor requires a room number and adds a Rs 400 surcharge to the regular hotel room rate based on the room number. Write a program to demonstrate creating and using an object of each class.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the Java code for the problem:

// Base class
public class HotelRoom {
    private int roomNumber;
    private double nightlyRentalRate;

    // Constructor
    public HotelRoom(int roomNumber) {
        this.roomNumber = roomNumber;
        if (roomNumber <= 100) {
            this.nightlyRentalRate = 500;
        } else {
            this.nightlyRentalRate = 800;
        }
    }

    // Getters
    public int getRoomNumber() {
        return roomNumber;
    }

    public double getNightlyRentalRate() {
        return nightlyRentalRate;
    }
}

// Extended class
public class Suite extends HotelRoom {
    // Constructor
    public Suite(int roomNumber) {
        super(roomNumber);
        double surcharge = 400;
        this.nightlyRentalRate += surcharge;
    }
}

// Main class to demonstrate the usage
public class Main {
    public static void main(String[] args) {
        HotelRoom hotelRoom = new HotelRoom(50);
        System.out.println("Hotel Room Number: " + hotelRoom.getRoomNumber());
        System.out.println("Hotel Room Rate: " + hotelRoom.getNightlyRentalRate());

        Suite suite = new Suite(150);
        System.out.println("Suite Room Number: " + suite.getRoomNumber());
        System.out.println("Suite Room Rate: " + suite.getNightlyRentalRate());
    }
}

This program first creates an object of the HotelRoom class with a room number of 50. It then prints out the room number and the nightly rental rate. After that, it creates an object of the Suite class with a room number of 150. It then prints out the room number and the nightly rental rate for the suite, which includes the surcharge.

This problem has been solved

Similar Questions

Hotel Management SystemTask Overview:To create a Java program for managing hotels using List and Set data structures. The program should allow users to perform operations such as adding hotels, removing hotels, searching for hotels, and displaying the list of hotels.Instructions:1. Hotel Class: - Create a Java class named Hotel with attributes such as name, location, rating, and price. - Implement appropriate constructor(s), getter and setter methods, and toString method for the Hotel class.2. Main Program: - In the main program, create a List to store hotels. - Utilize a Set to ensure that hotels with duplicate names cannot be added to the list. - Provide options for users to: - Add a new hotel to the list. - Remove a hotel from the list. - Search for a hotel by name or location. - Display the list of hotels with their details. - Exit the program.3. Input Handling: - Use Scanner for user input to add, remove, search, or display hotels. - Ensure error handling for invalid inputs and edge cases.4. Hotel Operations: - Implement methods to add a hotel, remove a hotel, search for a hotel, and display the list of hotels. - Use List and Set operations to perform these tasks efficiently.5. Testing: - Test the program by adding multiple hotels, searching for hotels, removing hotels, and displaying the list of hotels. - Verify that hotels with duplicate names are not added to the list.Sample OutputHotel Management System1. Add Hotel2. Remove Hotel3. Search Hotel4. Display All Hotels5. ExitEnter your choice: 1Enter hotel name: MidoriEnter hotel location: Clark, PampangaEnter hotel rating: 5Enter hotel price: 5500Hotel added successfully.Hotel Management System1. Add Hotel2. Remove Hotel3. Search Hotel4. Display All Hotels5. ExitEnter your choice: 1Enter hotel name: SogoEnter hotel location: Mabalacat City, PampangaEnter hotel rating: 3Enter hotel price: 800Hotel added successfully.Hotel Management System1. Add Hotel2. Remove Hotel3. Search Hotel4. Display All Hotels5. ExitEnter your choice: 1Enter hotel name: Bestwestern HotelEnter hotel location: Angeles City, PampangaEnter hotel rating: 4Enter hotel price: 2500Hotel added successfully.

Create a class for Electricity for N flats of an apartment. The required details are Flat number, EB meter number, Owner name, Previous month reading (in Units), current month reading (in Units), amount. Amount will be calculating as below:0-100 = Minimum charges ₹100101-500 = 2.5 ₹ per unit501-1000 = 5.0 ₹ per unitAbove 1000 =7.5 ₹ per unit                       Write appropriate functions to perform the following:Display the flat number, owner name, previous reading and current reading.Floor will be identified from the first digit of a flat number.  For 1001 – first floor, 2005 – second floor, 5010- Fifth floor. Display the floor wise details with total units and total amount. Input format:Enter the flat No:Enter the flat owner Name:Enter the previous reading:Enter the current reading: Output format:Total Units:Total amount:

Vehicle Rental SystemYou are designing a feature for the Vehicle Rental System that allows customers to calculate the total rental charge for a specific vehicle. The system provides a list of available vehicles, where each vehicle is represented by a tuple containing the vehicle's name, model, rental status, and price per day. The customer will select the vehicle by specifying the name and model, and then input the number of days they wish to rent the vehicle. Define a method calculate_rental_charge in the Vehicle_Rental_System class to calculate the rent for the vehicle for the given days and return the valueIf the vehicle is not available or vehicle model is not available then return -1Constraints:Input Format:The first line of input is name of the vehicleThe second line of input is model of the vehicleThe third line of input is no of days the customer want to take rentOutput Format:Single line of input displays charge for the no of days if not display -1Example:Sample Input 1:ToyotaCamry5Sample Output 1:250Explanation:Explanation:Toyota vehicle of Camry model is availableNo of days is 5 Charge is 5*50So, the output will be 250

Velan resort decides to automate their bookings. By automating they can easily enter the customer details, number of people visiting the resort, and based on the customer category they can calculate the booking price. So help the resort to do the automation using a Java programAssumptionPrice is in dollarsFor 1 adult 1000 per dayFor 1 child 650 per dayTake input from the user as a single string separating each field with a colon. <customer name>:<number of adults>:<number of child>:<number of days>Note:Customer category should be either "adult" or "child".If the number of adults is less than zero, print "Invalid input for number of adults"If the number of children is less than zero, print "Invalid input for number of children"If the number of days is less than or equal to zero, print "Invalid input for number of days"In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Do not use System.exit(0) to terminate the programSample Input/Output 1:Enter the customer detailsHarish:2:2:2Harish your booking is confirmed and the total cost is 6600Sample Input/Output 2:Enter the customer detailsGuru:1:0:0Invalid input for number of daysSample Input/Output 3:Ezhil:1:0:1Ezhil your booking is confirmed and the total cost is 1000

Experiment 1 PROGRAM TO GENERATE ELECTRICITY BILL AIM To develop a Java application to generate Electricity bill. PROCEDURE 1.Create a class with the following members Consumer no., consumer name, previous month reading, current month reading, type of EB connection (i.e domestic or commercial). 2.Compute the bill amount using the following tarif…

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.