import java.util.Scanner; import java.util.*; import java.util.*; public class Main { static final int MAX_BILL= 100; static Bill[] bills = new Bill[MAX_BILL]; static int billCount = 0; static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int choice; boolean flag = true; while(flag) { System.out.println("Bill Management System"); System.out.println("[1]Add Bill"); System.out.println("[2]Update amount details"); System.out.println("[3]Delete Bill details"); System.out.println("[4]Print all details "); System.out.println("[5]Exit"); try { choice = scanner.nextInt(); } catch (InputMismatchException e) { System.out.println("Invalid input. Please enter a number."); choice = 0; // Reset choice to avoid errors scanner.nextLine(); // Consume the newline character } switch (choice) { case 1: addBill(); break; case 2: updateBillAmount(billCount); break; case 3: deleteBill(); break; case 4: selectAllBill(billCount); break; case 5: System.out.println("Thank you"); flag=false; break; default: System.out.println("Invalid choice. Please try again."); } } } public static void addBill() { if (billCount < MAX_BILL) { System.out.print("Enter Consumer No: "); int consumerNo = scanner.nextInt();scanner.nextLine(); System.out.print("Enter Due Amount: "); double dueAmount = scanner.nextDouble();scanner.nextLine(); System.out.print("Enter Payable Amount: "); double payableAmount = scanner.nextDouble(); Bill bill = new Bill(consumerNo,dueAmount,payableAmount); bills[billCount++] = bill; System.out.println("Bill Registration is successful"); } else { System.out.println("Maximum number of bills reached. Cannot add more."); } } public static void deleteBill() { System.out.print("Enter Consumer No to delete: "); int consumerNoToDelete = scanner.nextInt(); scanner.nextLine(); // Consume the newline character for (int i = 0; i < billCount; i++) { if (bills[i].getConsumerNo() == consumerNoToDelete) { // Shift for (int j = i; j < billCount - 1; j++) { bills[j] = bills[j + 1]; } bills[--billCount] = null; // Remove the last element System.out.println("Customer details are deleted"); return; } } System.out.println("Customer not found with the given Consumer ID"); } public static void updateBillAmount (int billCount) { System.out.print("Enter Consumer No to update amount: "); int consumerNoToUpdate = scanner.nextInt(); scanner.nextLine(); System.out.print("Enter new Due Amount: "); double newDueAmount = scanner.nextDouble(); System.out.print("Enter new Payable Amount: "); double newPayableAmount = scanner.nextDouble(); for (int i = 0; i < billCount; i++) { if (bills[i].getConsumerNo() == consumerNoToUpdate) { bills[i].setDueAmount(newDueAmount); bills[i].setPayableAmount(newPayableAmount); System.out.println("Customer details are updated successfully"); return; } } System.out.println("Customer not found"); } public static void selectAllBill(int billCount) { System.out.println("All bill details:"); for (int i = 0; i < billCount; i++) { if(bills[i]!=null) { System.out.println("Complain type: "+ bills[i]. getConsumerNo()); System.out.println("Complain category: "+ bills[i].getDueAmount()); System.out.println("Landmark: "+ bills[i].getPayableAmount()); System.out.println(); System.out.println(); } } } } public class Bill { private int consumerNo; private double dueAmount; private double payableAmount; public Bill(int consumerNo, double dueAmount, double payableAmount) { this.consumerNo = consumerNo; this.dueAmount = dueAmount; this.payableAmount = payableAmount; } public int getConsumerNo() { return consumerNo; } public void setConsumerNo(int consumerNo) { this.consumerNo = consumerNo; } public double getDueAmount() { return dueAmount; } public void setDueAmount(double dueAmount) { this.dueAmount = dueAmount; } public double getPayableAmount() { return payableAmount; } public void setPayableAmount(double payableAmount) { this.payableAmount = payableAmount; } }