Home Java Programming Language / Programs / Shasha Travels Pvt. Ltd. provides discounts to its customers based on the ticket amount as follows:
🚀 Programming Example

Shasha Travels Pvt. Ltd. provides discounts to its customers based on the ticket amount as follows:

👁 113 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Shasha Travels Pvt. Ltd. provides discounts to its customers based on the ticket amount as follows:

Ticket Amount Range Discount
Above Rs. 70,000 18%
Rs. 55,001 to 70,000 16%
Rs. 35,001 to 55,000 12%
Rs. 25,001 to 35,000 10%
Less than Rs. 25,001 2%

Write a program to input the name and ticket amount for each customer, and calculate the discount amount and net amount to be paid. Display the output in the following format for each customer:

S. No. Name Ticket Amount Discount Net Amount
1 [Name] [Amount] [Discount] [Net]

(Assume that there are 15 customers, with the first customer given serial number 1, the next customer 2, and so on.)

Given Input:


Expected Output:


💻 Program Code

import java.io.*;

class Travels {
    // Arrays to store customer data
    String[] name = new String[15];
    double[] ticketAmount = new double[15];
    double[] discount = new double[15];
    double[] netAmount = new double[15];

    // Method to calculate discount and net amount
    void calculate() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        for (int i = 0; i < 15; i++) {
            System.out.println("Enter name for customer " + (i + 1) + ":");
            name[i] = br.readLine();
            System.out.println("Enter ticket amount for customer " + (i + 1) + ":");
            ticketAmount[i] = Double.parseDouble(br.readLine());

            // Calculate discount based on ticket amount
            if (ticketAmount[i] > 70000) {
                discount[i] = 0.18 * ticketAmount[i];
            } else if (ticketAmount[i] >= 55001 && ticketAmount[i] <= 70000) {
                discount[i] = 0.16 * ticketAmount[i];
            } else if (ticketAmount[i] >= 35001 && ticketAmount[i] <= 55000) {
                discount[i] = 0.12 * ticketAmount[i];
            } else if (ticketAmount[i] >= 25001 && ticketAmount[i] <= 35000) {
                discount[i] = 0.10 * ticketAmount[i];
            } else {
                discount[i] = 0.02 * ticketAmount[i];
            }

            // Calculate net amount
            netAmount[i] = ticketAmount[i] - discount[i];
        }
    }

    // Method to display customer data
    void display() {
        System.out.println("S. No.\tName\t\tTicket Amount\tDiscount\tNet Amount");
        for (int i = 0; i < 15; i++) {
            System.out.printf("%d\t%s\t\t%.2f\t\t%.2f\t\t%.2f%n", (i + 1), name[i], ticketAmount[i], discount[i], netAmount[i]);
        }
    }

    // Main method to create an object and call the methods
    public static void main(String[] args) throws IOException {
        Travels travels = new Travels();
        travels.calculate();
        travels.display();
    }
}

                        

📘 Explanation

Variable Table:

Variable Type Description
name[] String[] Array to store names of customers.
ticketAmount[] double[] Array to store ticket amounts for customers.
discount[] double[] Array to store discount amounts for each customer.
netAmount[] double[] Array to store net amounts to be paid by each customer.
i int Loop variable for iterating through customers.
br BufferedReader Used to read input from the console.

This code calculates the discount and net amount based on the given ticket amount ranges and displays the details in the specified format.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.