Association&Aggregation
Association&Aggregation
Infosys;
import java.util.Scanner;
// Aggregation: This kind of relationship exists when reference variable of one
class is member variable of another class.
// Order has a Food
// Association: Uses a relationship between two classes
class Order{
class Bill{
private int counter;
private String billId;
private String paymentMethod;
public Bill(String paymentMethod){
}
// boolean generateBill(Order order){ // The generate bill uses order object
to display the order details.
// System.out.println("Bill Details......");
// System.out.println("Bill ID: " + this.billId);
// System.out.println("Items Ordered: " );
// for(Food food : order.getOrderedFoods()){
// System.out.println(food.getFoodName());
// }
// }
}
class Food{
private String foodName;
private String cuisine;
private String foodType;
private int quantityAvailable;
private double unitPrice;
Order order = new Order(101, food); // here food object reference is passed
while creating Order object.
System.out.println("Order placed Successfully");
System.out.println("You have ordered: " +
order.getOrderedFoods().getFoodName());
System.out.println("Order Status: " + order.getStatus());