Table of Contents

64
UML Diagram to JAVA code [problem 2]
UML_ Problem 2

Item class java code

public class Item {
	protected int itemId;
	
	public Item(int itemId)
	{
		this.itemId=itemId;
	}
	public void display()
	{
		System.out.println("Item ID:"+itemId);
	}

}

Food class java code


public class Food extends Item {
	private String color;
	private double price;
	
	public Food(int itemId,String color,double price)
	{
		super(itemId);
		this.color=color;
		this.price=price;
		
	}
	public void display()
	{
		super.display();
		System.out.println("Color :"+color+"\n"+"Price :"+price);
	}

}

Customer class java code

public class Customer {
	Food food;
	protected int cusId;
	
	public Customer(Food food,int cusId)
	{
		this.food=food;
		this.cusId=cusId;
	}
	
	public void display()
	{
		food.display();
		System.out.println("Customer ID:"+cusId);
	}

}

Rahim Class java code


public class Rahim extends Customer{

	private String email;
	
	public Rahim(Food food,int cusId,String email)
	{
		super(food,cusId);
		this.email=email;
	}
	public void display()
	{
		super.display();
		System.out.println("Email :"+email);
	}
	public static void main(String[] args)
	{
		Food fd = new Food(1002,"Red",499);
		Rahim r =new  Rahim(fd,22,"rahim22@gmail.com");
		
		r.display();
	}
	

}

output

OUTPUT
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest
Share on whatsapp
WhatsApp
Share on email
Email
Md. Nurnobi Hosen
Md. Nurnobi Hosen

Student of Computer Science and Engineering at Daffodil International University,Main Campus ,Dhanmondi.
Web and App Developer also expart of wordpress customization

All Blog Posts »
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x