Skip to main content

KUKL customer system design and code

Short answer

Use case diagram: Customer, Staff, Admin, Payment Gateway actors; Register Connection, View Bill, Pay Bill (extended by Pay Electronically) etc. Class diagram: Customer–Bill 1–*, Bill–Payment 1–*, with CashPayment/ElectronicPayment subclasses. Code uses collections for associations and polymorphic payment processing.

Kathmandu Upatyaka Khane Pani Limited (KUKL) has hired you as a system analyst of an online customer management system and payment system. The system keeps track of all the customers and the payment they make for the service provided. The system has the option for electronic payment. Analyze and prepare the use case and design class diagram for the system. Map the design into code.

Assumptions: customers are registered with a connection; bills are generated monthly from meter readings; payment is made either in cash at the counter or electronically (card/e-wallet). Actors: Customer, Cashier/Staff, Admin, Payment Gateway (external).

Use case diagram

              +------------------------------+
              |   KUKL Customer Management   |
 [Customer] --|-( Register Connection )      |
 [Customer] --|-( View Bill )                |
 [Customer] --|-( Pay Bill )                 |
              |      ^ <<extend>>            |
              |      |                       |
              |  ( Pay Electronically )------|--[Payment Gateway]
 [Customer] --|-( View Payment History )     |
 [Staff] -----|-( Record Meter Reading )     |
 [Staff] -----|-( Generate Bill )            |
 [Staff] -----|-( Accept Cash Payment )      |
 [Admin] -----|-( Manage Customers )         |
 [Admin] -----|-( Generate Reports )         |
              +------------------------------+

Pay Bill is extended by Pay Electronically (an optional choice of payment mode). All customer use cases <<include>> a Login use case, which is left out of the diagram for clarity.

Design class diagram

 +---------------+ 1    * +----------------+
 | Customer      |--------|     Bill       |
 |---------------| gets   |----------------|
 | -id: int      |        | -billNo: int   |
 | -name: String |        | -month: String |
 | -address      |        | -units: double |
 | -connectionNo |        | -amount: double|
 |---------------|        | -paid: boolean |
 | +getBills()   |        |----------------|
 | +makePayment( |        | +calculate()   |
 |   bill, mode) |        +----------------+
 +---------------+               | 1
                                 | *
                      +------------------+
                      |    Payment       |
                      |------------------|
                      | -amount: double  |
                      | -date: Date      |
                      |------------------|
                      | +process()       |
                      +------------------+
                           ^         ^
                 CashPayment    ElectronicPayment
                                 -transactionId
                                 +process()

Mapping to code (Java)

import java.util.*;

class Customer {
    private int id;
    private String name, address, connectionNo;
    private List<Bill> bills = new ArrayList<>();       // 1 - *
    public Customer(int id, String name, String addr, String conn) {
        this.id = id; this.name = name; this.address = addr; this.connectionNo = conn;
    }
    public void addBill(Bill b) { bills.add(b); }
    public List<Bill> getBills() { return bills; }
    public void makePayment(Bill bill, Payment p) { bill.addPayment(p); }
}

class Bill {
    private int billNo; private String month;
    private double units, amount; private boolean paid;
    private List<Payment> payments = new ArrayList<>(); // 1 - *
    public Bill(int no, String month, double units) {
        this.billNo = no; this.month = month; this.units = units;
        this.amount = calculate();
    }
    public double calculate() { return units * 25.0; }  // assumed rate per unit
    public void addPayment(Payment p) {
        p.process();
        payments.add(p);
        double paidSum = 0;
        for (Payment x : payments) paidSum += x.getAmount();
        paid = paidSum >= amount;
    }
    public boolean isPaid() { return paid; }
}

abstract class Payment {
    protected double amount; protected Date date = new Date();
    public Payment(double amount) { this.amount = amount; }
    public double getAmount() { return amount; }
    public abstract void process();
}

class CashPayment extends Payment {
    public CashPayment(double a) { super(a); }
    public void process() { System.out.println("Cash received: " + amount); }
}

class ElectronicPayment extends Payment {
    private String transactionId;
    public ElectronicPayment(double a, String tid) { super(a); transactionId = tid; }
    public void process() { System.out.println("E-payment " + transactionId + ": " + amount); }
}

public class KuklApp {
    public static void main(String[] args) {
        Customer c = new Customer(1, "Hari", "Patan", "C-101");
        Bill b = new Bill(1001, "Baisakh", 20);
        c.addBill(b);
        c.makePayment(b, new ElectronicPayment(500, "TX77"));
        System.out.println("Paid: " + b.isPaid());
    }
}

The one-to-many associations (multiplicity 1 to *) became List fields; generalization became extends; and the abstract Payment.process() is overridden in each subclass (polymorphism). The payment mode in makePayment(bill, mode) is represented by passing a CashPayment or ElectronicPayment object.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Analysis and Design chapter 4 questions →