0% found this document useful (0 votes)
15 views7 pages

BILLINGSYSTEM

The document contains a Java program for a simple billing system that allows users to generate bills, display billing records, and save them to a text file. It defines a 'Bill' class to store bill details and a 'BillingSystem' class with a user interface for interaction. Users can create bills, view them, and save the records to a Notepad file, with error handling for file operations.

Uploaded by

skyneer18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

BILLINGSYSTEM

The document contains a Java program for a simple billing system that allows users to generate bills, display billing records, and save them to a text file. It defines a 'Bill' class to store bill details and a 'BillingSystem' class with a user interface for interaction. Users can create bills, view them, and save the records to a Notepad file, with error handling for file operations.

Uploaded by

skyneer18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

import java.io.

FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Scanner;

class Bill {

private int billNumber;

private String customerName;

private double totalAmount;

public Bill(int billNumber, String customerName, double totalAmount) {

this.billNumber = billNumber;

this.customerName = customerName;

this.totalAmount = totalAmount;

}
public int getBillNumber() {

return billNumber;

public String getCustomerName() {

return customerName;

public double getTotalAmount() {

return totalAmount;

public String getBillInfo() {

return "Bill Number: " + billNumber + ", Customer Name: " + customerName + ", Total Amount: $" +
totalAmount;
}

public class BillingSystem {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

ArrayList<Bill> bills = new ArrayList<>();

int billCounter = 1;

while (true) {

System.out.println("\n1. Generate Bill");

System.out.println("2. Display Billing Records");

System.out.println("3. Save Billing Records to Notepad");

System.out.println("4. Exit");

System.out.print("Enter your choice: ");


int choice = scanner.nextInt();

scanner.nextLine(); // Consume newline character

switch (choice) {

case 1:

System.out.print("Enter customer name: ");

String customerName = scanner.nextLine();

System.out.print("Enter total amount: $");

double totalAmount = scanner.nextDouble();

scanner.nextLine(); // Consume newline character

Bill bill = new Bill(billCounter, customerName, totalAmount);

bills.add(bill);

billCounter++;

System.out.println("Bill generated successfully!");

break;
case 2:

System.out.println("Billing Records:");

for (Bill b : bills) {

System.out.println(b.getBillInfo());

break;

case 3:

saveBillingRecordsToNotepad(bills);

System.out.println("Billing Records saved to Notepad successfully!");

break;

case 4:

System.out.println("Exiting billing system...");

System.exit(0);

break;

default:

System.out.println("Invalid choice! Please try again.");


}

private static void saveBillingRecordsToNotepad(ArrayList<Bill> bills) {

try {

FileWriter fileWriter = new FileWriter("billing_records.txt");

PrintWriter printWriter = new PrintWriter(fileWriter);

for (Bill bill : bills) {

printWriter.println(bill.getBillInfo());

printWriter.close();

} catch (IOException e) {
System.out.println("An error occurred while saving billing records to Notepad: " +
e.getMessage());

You might also like