0% found this document useful (0 votes)
91 views3 pages

CaseStudy Solution

This document defines classes for Items, Customers, Suppliers, and Orders to model a customer ordering system. A Customer can place Orders with a Supplier for Items. The Supplier receives the Order and both are added to their order lists. The main method demonstrates John and Alice placing Orders, which are received by supplier ABC Suppliers.

Uploaded by

nadia rehtika
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)
91 views3 pages

CaseStudy Solution

This document defines classes for Items, Customers, Suppliers, and Orders to model a customer ordering system. A Customer can place Orders with a Supplier for Items. The Supplier receives the Order and both are added to their order lists. The main method demonstrates John and Alice placing Orders, which are received by supplier ABC Suppliers.

Uploaded by

nadia rehtika
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/ 3

Solution//

import java.util.ArrayList;

class Item {
private int itemId;
private String itemName;
private int supplierId;

public Item(int itemId, String itemName, int supplierId) {


this.itemId = itemId;
this.itemName = itemName;
this.supplierId = supplierId;
}

public String getItemName() {


return itemName;
}

public int getSupplierId() {


return supplierId;
}
}
// Customer

class Customer {
private int customerId;
private String customerName;
private ArrayList<Order> orders;

public Customer(int customerId, String customerName) {


this.customerId = customerId;
this.customerName = customerName;
this.orders = new ArrayList<>();
}

public void placeOrder(Supplier supplier, Item item, int quantity) {


Order order = new Order(this, supplier, item, quantity);
orders.add(order);
supplier.receiveOrder(order);
System.out.println(customerName + " placed an order with " +
supplier.getSupplierName() + " for " + quantity + " " + item.getItemName());
}

public ArrayList<Order> getOrders() {


return orders;
}

String getCustomerName() {
return customerName;
}
}

// Supplier

class Supplier {
private int supplierId;
private String supplierName;
private ArrayList<Order> receivedOrders;

public Supplier(int supplierId, String supplierName) {


this.supplierId = supplierId;
this.supplierName = supplierName;
this.receivedOrders = new ArrayList<>();
}

public void receiveOrder(Order order) {


receivedOrders.add(order);
System.out.println(supplierName + " received an order from " +
order.getCustomer().getCustomerName());
}

public ArrayList<Order> getReceivedOrders() {


return receivedOrders;
}

public String getSupplierName() {


return supplierName;
}
}

// Order
class Order {
private Customer customer;
private Supplier supplier;
private Item item;
private int quantity;

public Order(Customer customer, Supplier supplier, Item item, int quantity) {


this.customer = customer;
this.supplier = supplier;
this.item = item;
this.quantity = quantity;
}

public Customer getCustomer() {


return customer;
}

public Supplier getSupplier() {


return supplier;
}

public Item getItem() {


return item;
}

public int getQuantity() {


return quantity;
}
}

public class Customer_Order {


/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Create a Supplier
Supplier supplier = new Supplier(101, "ABC Suppliers");

// Create Customers
Customer customer1 = new Customer(1, "John");
Customer customer2 = new Customer(2, "Alice");

// Create Items
Item item1 = new Item(1001, "Widget", 101); // Widget is supplied by
supplier with ID 101
Item item2 = new Item(1002, "Gadget", 101); // Gadget is also supplied by
supplier with ID 101

// John places an order for Widgets


customer1.placeOrder(supplier, item1, 5);

// Alice places an order for Gadgets


customer2.placeOrder(supplier, item2, 3);

// Display the received orders by the supplier


ArrayList<Order> supplierReceivedOrders;
supplierReceivedOrders = supplier.getReceivedOrders();
for (Order order : supplierReceivedOrders) {
System.out.println(supplier.getSupplierName() + " received an order for
" + order.getQuantity() + " " + order.getItem().getItemName() + " from " +
order.getCustomer().getCustomerName());
}
}

You might also like