Hotel Customer Inheritance | ISC Computer Science 2026 Theory

A superclass Hotel has been defined to store the details of a hotel. Define a subclass Customer to calculate the total bill for a customer as per the following criteria:

Room type        Additional Amount
Executive          10% of room rent
Suite                  20% of room rent

The details of the members of both the classes are given below:
Class name: Hotel
Data members/instance variables:
hname: to store hotel name
roomrent: to store the rent per day
Methods/Member functions:
Hotel(...): parameterized constructor to assign values to its data members
void show(): to display hotel details

Class name: Customer
Data members/instance variables:
cname: to store customer name
days: to store the number of days of stay
type: to store the room type
surcharge: to store the additional amount
amt: to store the total amount
Methods/Member functions:
Customer(...): parameterized constructor to assign values to data members of both the classes
void compute(): to calculate the surcharge based on the room type as given above. Also, to calculate the total amount as: (room rent + surcharge)  
× days
void show(): to display hotel and customer details

Assume that the superclass Hotel has been defined. Using the concept of Inheritance, specify the class Computer, giving details of constructor(...), void compute() and void show().

The super class, main() function and algorithm need not be written.

import java.util.Scanner;
class Hotel{
    protected String hname;
    protected double roomrent;
    public Hotel(String n, double r){
        hname = n;
        roomrent = r;
    }
    public void show(){
        System.out.println("Hotel name: " + hname);
        System.out.println("Room rent: " + roomrent);
    }
}
class Customer extends Hotel{
    String cname;
    int days;
    String type;
    double surcharge;
    double amt;
    public Customer(String n, double r, String cn, int d, String t){
        super(n, r);
        days = d;
        type = t;
    }
    public void compute(){
        if(type.equalsIgnoreCase("EXECUTIVE"))
            surcharge = 0.1 * roomrent;
        else if(type.equalsIgnoreCase("SUITE"))
            surcharge = 0.2 * roomrent;
        amt = (roomrent + surcharge) * days;
    }
    public void show(){
        super.show();
        System.out.println("Customer name: " + cname);
        System.out.println("Days of stay: " + days);
        System.out.println("Room type: " + type);
        System.out.println("Surcharge: " + surcharge);
        System.out.println("Amount: " + amt);
    }
}
class Inheritance{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.print("Hotel name: ");
        String hn = in.nextLine();
        System.out.print("Room rent: ");
        double rr = Double.parseDouble(in.nextLine());
        System.out.print("Customer name: ");
        String cn = in.nextLine();
        System.out.print("Days of stay: ");
        int d = Integer.parseInt(in.nextLine());
        System.out.print("Room type: ");
        String rt = in.nextLine();
        Customer obj = new Customer(hn, rr, cn, d, rt);
        obj.compute();
        obj.show();
    }
}

Comments