10 – Easy and simple java program for billing system of tour and travels

Java program for billing system of tour and travels

A Java program for simple tours and travels billing system.

Java program for billing system

import java.awt.event.*;
import javax.swing.*;
import java.util.*;
//itvoyagers.in
public class Ticket extends JFrame implements ActionListener
{
    int space = 30, age;
    float cost, total_service_tax = 0.0f, final_amount;
    
    JLabel ticket_name_label, non_ac_price_label, ac_price_label;
    JLabel name_label, age_label;
    JLabel name_list_label, age_list_label, cost_list_label;
    JLabel service_tax_text_label, service_tax, total_text_label, total;
//itvoyagers.in    
    JTextField name_text_field[] = new JTextField[3];
    JTextField age_text_field[] = new JTextField[3];
    
    JCheckBox ac;
    
    JButton book;
    
    JList name_list, age_list, price_list;
    
    DefaultListModel<String> name_bill, age_bill, price_bill;
//itvoyagers.in    
    public Ticket()
    {
        ticket_name_label = new JLabel("Mumbai To Pune");
        non_ac_price_label = new JLabel("Non-AC : ₹400/-");
        ac_price_label = new JLabel("AC : ₹550/-");
        
        name_label = new JLabel("Name");
        age_label = new JLabel("Age");
        
        name_list_label = new JLabel("Name");
        age_list_label = new JLabel("Age");
        cost_list_label = new JLabel("Cost");
        
        ac = new JCheckBox("AC");
        
        book = new JButton("Book");
//itvoyagers.in        
        service_tax_text_label = new JLabel("4% Service Tax");
        total_text_label = new JLabel("Total Amount");
        service_tax = new JLabel();
        total = new JLabel();
        
        name_bill = new DefaultListModel<>();
        age_bill = new DefaultListModel<>();
        price_bill = new DefaultListModel<>();
        
        name_list = new JList(name_bill);
        age_list = new JList(age_bill);
        price_list = new JList(price_bill);
        
        for (int i = 0; i < 3; i++)
        {
            name_text_field[i] = new JTextField();
            name_text_field[i].setBounds(10, (i+6)*10+space, 200, 20);
            add(name_text_field[i]);
            
            age_text_field[i] = new JTextField();
            age_text_field[i].setBounds(250, (i+6)*10+space, 100, 20);
            add(age_text_field[i]);
            
            space += 30;
        }
//itvoyagers.in        
        ticket_name_label.setBounds(140, 10, 200, 20);
        non_ac_price_label.setBounds(10, 40, 200, 20);
        ac_price_label.setBounds(250, 40, 100, 20);
        
        name_label.setBounds(10, 70, 50, 20);
        age_label.setBounds(250, 70, 50, 20);
        
        ac.setBounds(100, 199, 50, 20);
        
        book.setBounds(175, 195, 100, 30);
        
        name_list_label.setBounds(10, 230, 50, 20);
        age_list_label.setBounds(230, 230, 30, 20);
        cost_list_label.setBounds(300, 230, 50, 20);
        
        name_list.setBounds(10, 260, 200, 100);
        age_list.setBounds(230, 260, 50, 100);
        price_list.setBounds(300, 260, 50, 100);
        
        service_tax_text_label.setBounds(100, 370, 100, 20);
        total_text_label.setBounds(100, 390, 100, 20);
        service_tax.setBounds(300, 370, 100, 20);
        total.setBounds(300, 390, 100, 20);
//itvoyagers.in        
        add(ticket_name_label);
        add(non_ac_price_label);
        add(ac_price_label);
        
        add(name_label);
        add(age_label);
        
        add(ac);
        
        add(book);
        
        add(name_list_label);
        add(age_list_label);
        add(cost_list_label);
        
        add(name_list);
        add(age_list);
        add(price_list);
        
        add(service_tax_text_label);
        add(total_text_label);
        add(service_tax);
        add(total);
        
        book.addActionListener(this);
//itvoyagers.in        
        setSize(375,460);
        setLayout(null);
        setVisible(true);
        setTitle("My Ticket");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    @Override
    public void actionPerformed(ActionEvent e) 
    {
        if(e.getSource()==book)
        {
            float amount_without_service_tax = 0.0f;
            
            clear_all();
            
            cost = ac.isSelected() ? 550 : 400;
//itvoyagers.in            
            for(int i = 0; i < 3; i++)
            {                
                try
                {
                    age = Integer.parseInt(age_text_field[i].getText());
                    
                    if((age < 5 || age > 65) && age<100)
                    {
                        price_bill.addElement(Float.toString(cost/2));
                    }
                    else if(age>=5 && age<=65)
                    {
                        price_bill.addElement(Float.toString(cost));
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(this, "Please enter valid age");
                        age_text_field[i].setText("");
                        break;
                    }
                    
                    name_bill.addElement(name_text_field[i].getText());
                    age_bill.addElement(age_text_field[i].getText());
                }
                catch(NumberFormatException exp)
                {
                    JOptionPane.showMessageDialog(this, "Something went worngn1. Please check for blank fieldsn2. Please enter numeric values in age");
                    age_text_field[i].setText("");
                    clear_all();
                    break;
                }
            }
//itvoyagers.in            
            for(int i=0;i<price_bill.getSize();i++)
            {
                amount_without_service_tax += Float.parseFloat(price_bill.getElementAt(i));
            }
            
            total_service_tax = amount_without_service_tax * 0.04f;
            final_amount = amount_without_service_tax + total_service_tax;
            
            service_tax.setText(Float.toString(total_service_tax));
            total.setText(Float.toString(final_amount));
        }
    }
//itvoyagers.in    
    public void clear_all()
    {
            name_bill.clear();
            age_bill.clear();
            price_bill.clear();
    }
//itvoyagers.in
    public static void main(String[] args)
    {
        Ticket ticket = new Ticket();
    }
}

Output

java program for billing system itvoyagers

PRACTICALS/PRACTICE PROGRAM IN Java

SYIT Practical Programs
SY-1-a Easy Java program to print multiplication table
SY-1-b Easy program to print inverted pyramid pattern of stars in Java
SY-1-c Easy Java program to print the area and perimeter of a circle
SY-2-c Easy Java program to reverse a string
SY-3-a Easy Java program to count the letters, spaces, numbers and other characters
SY-3-c Easy to find the smallest and largest element from the array in Java
SY-4-a Easy java program to sort array in ascending and descending order
SY-4-b Easy program on constructor and destructor in Java
SY-4-c Implementation of abstract class in Java in easy way
SY-5-a Easy java program to implement single level inheritance
SY-5-b Easy java program to implement method overriding
SY-5-c Easy java program to implement multiple inheritance
SY-6-a Easy program to create package in Java
SY-6-b easy java program to add two matrices and print the resultant matrix
SY-6-c Java program for multiplying two matrices in easy way
SY-7-a easy java program to implement the vectors
SY-7-c Easy and simple java program to implement multithreading
SY-8-a java program to open a file and display the contents in the console window in easy way
SY-8-b Java program to copy the contents from one file to other file in easy way
SY-9-a Java AWT program to print the factorial for an input value in easy way
SY-9-b Java AWT program to perform various string operations in easy way
SY-9-c Easy java program to implement exception handling
SY-10-a Java AWT program to accept and display student details in easy way
ST-10-b Java program to design a calculator based on AWT application in easy way
SYCS Practical Programs Semester 3
Java program to solve quadratic equations to print the roots of ax2+bx+c=0
Java program to add two matrices
Accept n strings. Sort names in ascending order
Create a package: Animals. In package animals create interface Animal with suitable behaviors. Implement the interface Animal in the same package animals
Demonstrate Java inheritance using extends keyword.
Demonstrate method overloading and method overriding in Java.
Demonstrate creating your own exception in Java.
Using various swing components design Java application to accept a student’s resume. (Design form)
Write a Java List example and demonstrate methods of Java List interface.
Design simple calculator GUI application using AWT components
Write a Java program that takes a number as input and prints its multiplication table upto 10.
Java program to print reverse pyramid
Write a Java program to print the area and perimeter of a circle
SYCS Practical Programs Semester 4
SYCS-5 Java application to demonstrate servlet life cycle in easy way
Practice Program
1 – Best Java program to find factorial of a number
2 – Java program to check if number is Even or Odd
3 – Best Java program to check prime number
4 – Simple and easy Java program to calculate area
5 – Best Java program to convert decimal to binary
6 – Best Java program to implement stack using array
7 – Best Java program to check palindrome number
8 – Best Java program to reverse a number
9 – Easy and simple billing system program in java swing
10 – Easy and simple java program for billing system of tour and travels
More coming soon…

CHECKOUT OTHER RELATED TOPICS

We are aiming to explain all concepts of Java in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment