0% found this document useful (0 votes)
1 views2 pages

Customer Management System by Java Code

The document contains a Java program that manages customer information using a Customer class and a CustomerManager class. It allows for adding, updating, deleting, and listing customers through a simple console interface. The program utilizes an ArrayList to store customer objects and provides methods for various customer operations.

Uploaded by

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

Customer Management System by Java Code

The document contains a Java program that manages customer information using a Customer class and a CustomerManager class. It allows for adding, updating, deleting, and listing customers through a simple console interface. The program utilizes an ArrayList to store customer objects and provides methods for various customer operations.

Uploaded by

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

import java.util.

ArrayList;
import java.util.Scanner;

class Customer {
private int id;
private String name;
private String address;

public Customer(int id, String name, String address) {


this.id = id;
this.name = name;
this.address = address;
}

public int getId() {


return id;
}

public void setId(int id) {


this.id = id;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getAddress() {


return address;
}

public void setAddress(String address) {


this.address = address;
}
}

class CustomerManager {
ArrayList<Customer> customers;

public CustomerManager() {
customers = new ArrayList<Customer>();
}

public void addCustomer(int id, String name, String address) {


Customer customer = new Customer(id, name, address);
customers.add(customer);
}

public Customer findCustomerById(int id) {


for (Customer customer : customers) {
if (customer.getId() == id) {
return customer;
}
}
return null;
}
public void updateCustomer(int id, String name, String address) {
Customer customer = findCustomerById(id);
if (customer != null) {
customer.setName(name);
customer.setAddress(address);
}
}

public void deleteCustomer(int id) {


Customer customer = findCustomerById(id);
if (customer != null) {
customers.remove(customer);
}
}

public void listCustomers() {


for (Customer customer : customers) {
System.out.println("ID: " + customer.getId());
System.out.println("Name: " + customer.getName());
System.out.println("Address: " + customer.getAddress());
System.out.println("-------------");
}
}
}

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
CustomerManager customerManager = new CustomerManager();
int id;
String name;
String address;

while (true) {
System.out.println("1. Add Customer");
System.out.println("2. Update Customer");
System.out.println("3. Delete Customer");
System.out.println("4. List Customers");
System.out.println("0. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();

switch (choice) {
case 1:
System.out.print("Enter id: ");
id = scanner.nextInt();
System.out.print("Enter name: ");
name = scanner.nextLine();
System.out.print("Enter address: ");
}}}}

You might also like