E Commerce Order System

This program models an e commerce order system.

Problem Statement

Write a Java program to model Product and Order classes with interaction.

Source Code

1 class Product {
2 String name; double price;
3 Product(String n,double p){ name=n; price=p; }
4 }
5 class Order {
6 Product product; int quantity;
7 Order(Product p,int q){ product=p; quantity=q; }
8 void showOrder(){
9 System.out.println("Order: "+product.name+", Quantity: "+quantity+", Total: "+(product.price*quantity));
10 }
11 }
12 public class EcommerceOrderSystem {
13 public static void main(String[] args) {
14 System.out.println("Eduinq E Commerce Order System");
15 Product p=new Product("Laptop",50000);
16 Order o=new Order(p,2);
17 o.showOrder();
18 }
19 }

Program Output

Eduinq E Commerce Order System
Order: Laptop, Quantity: 2, Total: 100000.0

Explanation

Product class models item with name and price. - Order class associates product with quantity. - Interaction calculates total cost. - This demonstrates how OOP can model real world e commerce systems with encapsulation and association. Conclusion: Shows how to model e commerce order system using OOP.

Quick Links to Explore