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

Association&Aggregation

Uploaded by

Vinay Shewale
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)
30 views3 pages

Association&Aggregation

Uploaded by

Vinay Shewale
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

package com.

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{

private int orderId;


private Food orderedFoods; // here food is a reference variable of food class
and is member variable of order class.
private double totalPrice;
private String status;

public Order(int orderId, Food orderedFoods){


this.orderId = orderId;
this.orderedFoods = orderedFoods;
this.status = "Ordered";
}

public int getOrderId() {


return orderId;
}

public void setOrderId(int orderId) {


this.orderId = orderId;
}

public Food getOrderedFoods() {


return orderedFoods;
}

public void setOrderedFoods(Food orderedFoods) {


this.orderedFoods = orderedFoods;
}

public double getTotalPrice() {


return totalPrice;
}

public void setTotalPrice(double totalPrice) {


this.totalPrice = totalPrice;
}

public String getStatus() {


return status;
}

public void setStatus(String status) {


this.status = status;
}

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;

public void setFoodName(String foodName){


this.foodName = foodName;
}
public String getFoodName(){
return foodName;
}

public String getCuisine() {


return cuisine;
}

public void setCuisine(String cuisine) {


this.cuisine = cuisine;
}

public String getFoodType() {


return foodType;
}

public void setFoodType(String foodType) {


this.foodType = foodType;
}

public int getQuantityAvailable() {


return quantityAvailable;
}

public void setQuantityAvailable(int quantityAvailable) {


this.quantityAvailable = quantityAvailable;
}

public double getUnitPrice() {


return unitPrice;
}

public void setUnitPrice(double unitPrice) {


this.unitPrice = unitPrice;
}
}

public class Main {

public static void main(String[] args) {


// The Food object and Order object both will exist independently
// & you need to pass Food object while creating Order object
Food food = new Food();
food.setFoodName("Pizza");
food.setCuisine("Italian");
food.setFoodType("Veg");
food.setQuantityAvailable(10);
food.setUnitPrice(8.0);

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());

You might also like