package com.crm.
management;
import java.util.*;
// Custom Exceptions
class InvalidCustomerException extends Exception {
public InvalidCustomerException(String message) {
super(message);
}
}
class DuplicateLeadException extends Exception {
public DuplicateLeadException(String message) {
super(message);
}
}
// Customer Class
class Customer {
private int id;
private String name;
private String contact;
private List<String> history;
public Customer(int id, String name, String contact) {
this.id = id;
this.name = name;
this.contact = contact;
this.history = new ArrayList<>();
}
public int getId() { return id; }
public String getName() { return name; }
public String getContact() { return contact; }
public void addHistory(String record) { history.add(record); }
public List<String> getHistory() { return history; }
}
// Inheritance Example
class CorporateCustomer extends Customer {
private String companyName;
public CorporateCustomer(int id, String name, String contact, String companyName) {
super(id, name, contact);
this.companyName = companyName;
}
public String getCompanyName() { return companyName; }
}
class IndividualCustomer extends Customer {
public IndividualCustomer(int id, String name, String contact) {
super(id, name, contact);
}
}
// Lead Class
class Lead {
private int id;
private String potentialCustomer;
public Lead(int id, String potentialCustomer) {
this.id = id;
this.potentialCustomer = potentialCustomer;
}
public int getId() { return id; }
public String getPotentialCustomer() { return potentialCustomer; }
}
// Sales Representative
class SalesRepresentative {
private int id;
private String name;
private List<Customer> assignedCustomers;
public SalesRepresentative(int id, String name) {
this.id = id;
this.name = name;
this.assignedCustomers = new ArrayList<>();
}
public void assignCustomer(Customer customer) {
assignedCustomers.add(customer);
}
public List<Customer> getAssignedCustomers() {
return assignedCustomers;
}
}
// Service Request (Polymorphism Example)
abstract class ServiceRequest {
protected int requestId;
protected Customer customer;
protected String issue;
public ServiceRequest(int requestId, Customer customer, String issue) {
this.requestId = requestId;
this.customer = customer;
this.issue = issue;
}
public abstract void resolve();
}
class PhoneSupport extends ServiceRequest {
public PhoneSupport(int requestId, Customer customer, String issue) {
super(requestId, customer, issue);
}
@Override
public void resolve() {
System.out.println("Phone support resolving issue: " + issue);
}
}
class EmailSupport extends ServiceRequest {
public EmailSupport(int requestId, Customer customer, String issue) {
super(requestId, customer, issue);
}
@Override
public void resolve() {
System.out.println("Email support resolving issue: " + issue);
}
}
// Invoice Class
class Invoice {
private int invoiceId;
private Customer customer;
private double amount;
public Invoice(int invoiceId, Customer customer, double amount) {
this.invoiceId = invoiceId;
this.customer = customer;
this.amount = amount;
}
public void generateInvoice() {
System.out.println("Invoice generated for customer: " + customer.getName() + ", Amount: " + amount);
}
}
// Main CRM System
public class CRMSystem {
private List<Customer> customers = new ArrayList<>();
private Map<Integer, ServiceRequest> serviceRequests = new HashMap<>();
private Queue<Lead> leads = new LinkedList<>();
public void addCustomer(Customer customer) throws InvalidCustomerException {
for (Customer c : customers) {
if (c.getId() == customer.getId()) {
throw new InvalidCustomerException("Customer with ID " + customer.getId() + " already exists.");
}
}
customers.add(customer);
}
public void addLead(Lead lead) throws DuplicateLeadException {
for (Lead l : leads) {
if (l.getId() == lead.getId()) {
throw new DuplicateLeadException("Lead with ID " + lead.getId() + " already exists.");
}
}
leads.add(lead);
}
public void createServiceRequest(ServiceRequest request) {
serviceRequests.put(request.requestId, request);
}
public static void main(String[] args) {
CRMSystem crm = new CRMSystem();
try {
Customer c1 = new IndividualCustomer(1, "John Doe", "[email protected]");
crm.addCustomer(c1);
crm.createServiceRequest(new PhoneSupport(101, c1, "Internet not working"));
crm.serviceRequests.get(101).resolve();
} catch (InvalidCustomerException e) {
System.out.println("Error: " + e.getMessage());
}
}
}