Write a Java program to manage billing information for customers. The program should allow the user to input details for multiple customers and bills. For each customer, the program should prompt the user to enter a customer ID and name. For each bill, the program should prompt the user to enter a bill number, amount, date, and the corresponding customer ID. Once the user has input all the necessary information, the program should allow the user to search for bills by customer ID. Upon entering a customer ID, the program should display all bill amounts, dates, and numbers associated with that customer ID. Frame the program using classes for Customer and Bill, and implement methods to retrieve customer and bill details. Sample Input 3 // Number of Customers 1 // Customer IDJai // Customer Name 2Sakthi 3John 5 // Number of Bills 11 // Bill Number45663 // Bill Amount02/12/2023 // Bill Date2 // Customer ID 4489609/12/20232 77896509/04/20231 99675404/11/20221 33876511/11/202332 Sample Output 1145663.002/12/202344896.009/12/2023
Question
Write a Java program to manage billing information for customers. The program should allow the user to input details for multiple customers and bills. For each customer, the program should prompt the user to enter a customer ID and name. For each bill, the program should prompt the user to enter a bill number, amount, date, and the corresponding customer ID. Once the user has input all the necessary information, the program should allow the user to search for bills by customer ID. Upon entering a customer ID, the program should display all bill amounts, dates, and numbers associated with that customer ID. Frame the program using classes for Customer and Bill, and implement methods to retrieve customer and bill details. Sample Input 3 // Number of Customers 1 // Customer IDJai // Customer Name 2Sakthi 3John 5 // Number of Bills 11 // Bill Number45663 // Bill Amount02/12/2023 // Bill Date2 // Customer ID 4489609/12/20232 77896509/04/20231 99675404/11/20221 33876511/11/202332 Sample Output 1145663.002/12/202344896.009/12/2023
Solution 1
Here is a simple Java program that meets your requirements:
import java.util.*;
class Customer {
int id;
String name;
ArrayList<Bill> bills;
Customer(int id, String name) {
this.id = id;
this.name = name;
this.bills = new ArrayList<>();
}
}
class Bill {
int number;
double amount;
String date;
Bill(int number, double amount, String date) {
this.number = number;
this.amount = amount;
this.date = date;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
HashMap<Integer, Customer> customers = new HashMap<>();
System.out.println("Enter number of customers:");
int numCustomers = sc.nextInt();
for (int i = 0; i < numCustomers; i++) {
System.out.println("Enter customer ID and name:");
int id = sc.nextInt();
String name = sc.next();
customers.put(id, new Customer(id, name));
}
System.out.println("Enter number of bills:");
int numBills = sc.nextInt();
for (int i = 0; i < numBills; i++) {
System.out.println("Enter bill number, amount, date, and customer ID:");
int number = sc.nextInt();
double amount = sc.nextDouble();
String date = sc.next();
int customerId = sc.nextInt();
if (customers.containsKey(customerId)) {
customers.get(customerId).bills.add(new Bill(number, amount, date));
}
}
System.out.println("Enter customer ID to search bills:");
int searchId = sc.nextInt();
if (customers.containsKey(searchId)) {
for (Bill bill : customers.get(searchId).bills) {
System.out.println(bill.number + " " + bill.amount + " " + bill.date);
}
} else {
System.out.println("No bills found for this customer ID.");
}
}
}
This program first prompts the user to enter the number of customers and their details. It then prompts the user to enter the number of bills and their details. Finally, it prompts the user to enter a customer ID to search for bills. If the customer ID exists, it prints all the bills associated with that customer ID. If the customer ID does not exist, it prints a message saying no bills were found.
Solution 2
Here is a simple Java program that meets your requirements:
import java.util.*;
class Customer {
int id;
String name;
ArrayList<Bill> bills;
Customer(int id, String name) {
this.id = id;
this.name = name;
this.bills = new ArrayList<>();
}
}
class Bill {
int number;
double amount;
String date;
Bill(int number, double amount, String date) {
this.number = number;
this.amount = amount;
this.date = date;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HashMap<Integer, Customer> customers = new HashMap<>();
System.out.println("Enter number of customers:");
int numCustomers = scanner.nextInt();
for (int i = 0; i < numCustomers; i++) {
System.out.println("Enter customer ID and name:");
int id = scanner.nextInt();
String name = scanner.next();
customers.put(id, new Customer(id, name));
}
System.out.println("Enter number of bills:");
int numBills = scanner.nextInt();
for (int i = 0; i < numBills; i++) {
System.out.println("Enter bill number, amount, date, and customer ID:");
int number = scanner.nextInt();
double amount = scanner.nextDouble();
String date = scanner.next();
int customerId = scanner.nextInt();
customers.get(customerId).bills.add(new Bill(number, amount, date));
}
System.out.println("Enter customer ID to search bills:");
int searchId = scanner.nextInt();
for (Bill bill : customers.get(searchId).bills) {
System.out.println(bill.number + " " + bill.amount + " " + bill.date);
}
}
}
This program first prompts the user to enter the number of customers and their details. It then prompts the user to enter the number of bills and their details, associating each bill with a customer. Finally, it prompts the user to enter a customer ID and displays all bills associated with that customer.
Solution 3
Here is a simple Java program that meets your requirements:
import java.util.*;
class Customer {
int id;
String name;
ArrayList<Bill> bills;
Customer(int id, String name) {
this.id = id;
this.name = name;
this.bills = new ArrayList<>();
}
}
class Bill {
int number;
double amount;
String date;
Bill(int number, double amount, String date) {
this.number = number;
this.amount = amount;
this.date = date;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HashMap<Integer, Customer> customers = new HashMap<>();
System.out.println("Enter number of customers:");
int numCustomers = scanner.nextInt();
for (int i = 0; i < numCustomers; i++) {
System.out.println("Enter customer ID and name:");
int id = scanner.nextInt();
String name = scanner.next();
customers.put(id, new Customer(id, name));
}
System.out.println("Enter number of bills:");
int numBills = scanner.nextInt();
for (int i = 0; i < numBills; i++) {
System.out.println("Enter bill number, amount, date, and customer ID:");
int number = scanner.nextInt();
double amount = scanner.nextDouble();
String date = scanner.next();
int customerId = scanner.nextInt();
Bill bill = new Bill(number, amount, date);
customers.get(customerId).bills.add(bill);
}
System.out.println("Enter customer ID to search bills:");
int searchId = scanner.nextInt();
for (Bill bill : customers.get(searchId).bills) {
System.out.println(bill.number + " " + bill.amount + " " + bill.date);
}
}
}
This program first prompts the user to enter the number of customers and their details. It then prompts the user to enter the number of bills and their details, including the customer ID to which each bill is associated. Finally, it prompts the user to enter a customer ID to search for bills, and it displays all bills associated with that customer ID.
Solution 4
Here is a simple Java program that meets your requirements:
import java.util.*;
class Customer {
int id;
String name;
ArrayList<Bill> bills;
Customer(int id, String name) {
this.id = id;
this.name = name;
this.bills = new ArrayList<>();
}
}
class Bill {
int number;
double amount;
String date;
Bill(int number, double amount, String date) {
this.number = number;
this.amount = amount;
this.date = date;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HashMap<Integer, Customer> customers = new HashMap<>();
System.out.println("Enter number of customers:");
int numCustomers = scanner.nextInt();
for (int i = 0; i < numCustomers; i++) {
System.out.println("Enter customer ID and name:");
int id = scanner.nextInt();
String name = scanner.next();
customers.put(id, new Customer(id, name));
}
System.out.println("Enter number of bills:");
int numBills = scanner.nextInt();
for (int i = 0; i < numBills; i++) {
System.out.println("Enter bill number, amount, date, and customer ID:");
int number = scanner.nextInt();
double amount = scanner.nextDouble();
String date = scanner.next();
int customerId = scanner.nextInt();
if (customers.containsKey(customerId)) {
customers.get(customerId).bills.add(new Bill(number, amount, date));
}
}
System.out.println("Enter customer ID to search bills:");
int searchId = scanner.nextInt();
if (customers.containsKey(searchId)) {
for (Bill bill : customers.get(searchId).bills) {
System.out.println(bill.number + " " + bill.amount + " " + bill.date);
}
} else {
System.out.println("No bills found for this customer ID.");
}
}
}
This program first prompts the user to enter the number of customers and their details. It then prompts the user to enter the number of bills and their details. Finally, it prompts the user to enter a customer ID to search for bills. If the customer ID exists, it prints all the bills associated with that customer ID. Otherwise, it prints a message saying no bills were found for that customer ID.
Solution 5
Here is a simple Java program that meets your requirements:
import java.util.*;
class Customer {
int id;
String name;
ArrayList<Bill> bills;
Customer(int id, String name) {
this.id = id;
this.name = name;
this.bills = new ArrayList<>();
}
}
class Bill {
int number;
double amount;
String date;
Bill(int number, double amount, String date) {
this.number = number;
this.amount = amount;
this.date = date;
}
}
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
HashMap<Integer, Customer> customers = new HashMap<>();
System.out.println("Enter number of customers:");
int numCustomers = scanner.nextInt();
for (int i = 0; i < numCustomers; i++) {
System.out.println("Enter customer ID and name:");
int id = scanner.nextInt();
String name = scanner.next();
customers.put(id, new Customer(id, name));
}
System.out.println("Enter number of bills:");
int numBills = scanner.nextInt();
for (int i = 0; i < numBills; i++) {
System.out.println("Enter bill number, amount, date, and customer ID:");
int number = scanner.nextInt();
double amount = scanner.nextDouble();
String date = scanner.next();
int customerId = scanner.nextInt();
if (customers.containsKey(customerId)) {
customers.get(customerId).bills.add(new Bill(number, amount, date));
}
}
System.out.println("Enter customer ID to search bills:");
int searchId = scanner.nextInt();
if (customers.containsKey(searchId)) {
for (Bill bill : customers.get(searchId).bills) {
System.out.println(bill.number + " " + bill.amount + " " + bill.date);
}
} else {
System.out.println("No bills found for this customer ID.");
}
}
}
This program first prompts the user to enter the number of customers and their details. It then prompts the user to enter the number of bills and their details. Finally, it prompts the user to enter a customer ID to search for bills. If the customer ID exists, it prints all the bills associated with that customer ID. If the customer ID does not exist, it prints a message saying no bills were found.
Similar Questions
Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance.Input 1:Enter the customers:ReenaSavings1231000RobinCurrent4562000PraveenSavings7893000SherinCurrent2342500DeenaSavings5672000Enter choice:1. Credit2. Debit Output :ReenaSavings1232000
Design a Java program to process loan applications for customers. Each loan application includes details such as the applicant's name, salary, and loan amount. The program evaluates each loan application based on certain criteria. If the applicant's salary is greater than $50,000 and the requested loan amount is within twice the applicant's salary, the loan application is approved; otherwise, it is rejected. Implement the program using classes and objects. Write a Java code that performs the following tasks: Define a class LoanApplication with private fields for the applicant's name, salary, loan amount, and loan approval status.Implement a constructor to initialize the loan application details.Create a method processLoan() to evaluate the loan application based on the specified criteria.Define a class Loan with a main method to interact with the user.Prompt the user to input details for multiple loan applications.Process each loan application and display whether it is approved or rejected.Additionally, display the names, salaries, and loan amounts of customers whose loan applications are approved.Demonstrate the functionality of your program with a sample input/output scenario.
To develop a Java application to generate Electricity bill. Create a class with the following members: Consumer no., consumer name, previous month reading, current month reading, type of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff.
Consider a ticket reservation system that allows users to book tickets for various destinations. Each ticket has details such as passenger name, destination, ticket price, and passenger age. The ticket prices are calculated based on the passenger's age, with children (age <= 12) receiving a 50% discount, senior citizens (age >= 60) receiving a 30% discount, and others paying the regular price. The system also tracks the confirmation status of each ticket.Design a Java program that implements this ticket reservation system. The program should prompt the user to input details for multiple tickets, including passenger name, destination, ticket price, and passenger age. It should then calculate and display the total amount of tickets booked for confirmed tickets alone, considering the discounted prices based on passenger age.Write the Java code for the ticket reservation system and demonstrate its functionality with a sample input/output scenario.Sample Input: 3 //No of tickets to book Ravi // NameDelhi // Destination2000 // Price70 // Age Manu // NameDelhi // Destination2000 // Price9 // Age Priya // NameDelhi // Destination2000 // Price40 // Ageconfirm // Do you want to confirm or cancel ticket 1? (confirm/cancel)cancel // Do you want to confirm or cancel this ticket 2? (confirm/cancel)confirm // Do you want to confirm or cancel this ticket 3? (confirm/cancel)Sample Output:3400.0 // Total Amount of Confirmed Tickets
Define a class named Customer that holds private fields for a customer ID number, last name, first name, and credit limit. Include four public functions that each set one of the four fields. Do not allow any credit limit over $10,000. Include a public function that displays a Customer’s data.a. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.b. Write a main()function that declares an array of five Customer objects. Prompt the user for values for each Customer, and display all five Customer objects
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.