C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Introduction to Java

Java Program: Hotel Bill Calculator with Discounts

Assumptions

Total Amount

Discount

Above ₹5000

20%

₹3000–₹5000

10%

₹1000–₹3000

5%

Below ₹1000

No discount

You can change these thresholds anytime.

 

import java.util.Scanner;

 

public class HotelBillCalculator {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter Customer Name: ");

        String name = sc.nextLine();

 

        System.out.print("Enter Room Charge per Night: ");

        double roomCharge = sc.nextDouble();

 

        System.out.print("Enter Number of Nights: ");

        int nights = sc.nextInt();

 

        System.out.print("Enter Food Bill: ");

        double foodBill = sc.nextDouble();

 

        System.out.print("Enter Additional Services Charge (Spa, Laundry, etc.): ");

        double services = sc.nextDouble();

 

        // Total before discount

        double total = (roomCharge * nights) + foodBill + services;

 

        // Discount Calculation

        double discount = 0;

 

        if (total > 5000) {

            discount = total * 0.20;  // 20%

        } else if (total >= 3000) {

            discount = total * 0.10;  // 10%

        } else if (total >= 1000) {

            discount = total * 0.05;  // 5%

        }

 

        double finalAmount = total - discount;

 

        // Output Bill

        System.out.println("\n------------ HOTEL BILL ------------");

        System.out.println("Customer Name        : " + name);

        System.out.println("Room Charge per Night: ₹" + roomCharge);

        System.out.println("Nights Stayed        : " + nights);

        System.out.println("Food Bill            : ₹" + foodBill);

        System.out.println("Other Services       : ₹" + services);

        System.out.println("------------------------------------");

        System.out.println("Total Amount         : ₹" + total);

        System.out.println("Discount Applied     : ₹" + discount);

        System.out.println("------------------------------------");

        System.out.println("Final Payable Amount : ₹" + finalAmount);

        System.out.println("------------------------------------");

 

        sc.close();

    }

}

Output

 
OUTPUT :
Enter Customer Name: Riya Sharma
Enter Room Charge per Night: 1500
Enter Number of Nights: 2
Enter Food Bill: 1200
Enter Additional Services Charge (Spa, Laundry, etc.): 800

------------ HOTEL BILL ------------
Customer Name        : Riya Sharma
Room Charge per Night: ₹1500.0
Nights Stayed        : 2
Food Bill            : ₹1200.0
Other Services       : ₹800.0
------------------------------------
Total Amount         : ₹5000.0
Discount Applied     : ₹500.0
------------------------------------
Final Payable Amount : ₹4500.0
------------------------------------

Explanation

1. Inputs Taken

  • Customer name
  • Room charge per night
  • Number of nights stayed
  • Food bill amount
  • Additional service charges

2. Total Amount Calculation

total = (roomCharge × nights) + foodBill + services

3. Discount Rules

The program checks the total and applies:

  • 20% for total > 5000
  • 10% for total between 3000–5000
  • 5% for total between 1000–3000
  • 0% for total < 1000

4. Final Bill Calculation

finalAmount = total − discount

5. Output

A complete, formatted hotel bill is displayed.