UML Diagram to JAVA code [problem 1]

Problem1_UML_Diagram
Generally, UML diagrams are not directly mapped with any object-oriented programming languages but the class diagram is an exception. Class diagram clearly shows the mapping with object-oriented languages such as Java, C++, etc. From practical experience, class diagram is generally used for construction purpose.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email
61
Problem 1 Diagram

Human Class Source code


public class Human {
	protected String scientificName;
	
	public Human(String scientificName)
	{
		this.scientificName = scientificName;
	}
	public void display()
	{
		System.out.println("Scientific Name:"+scientificName);
	}

}

Item Class source code


public class Item {
	public int itemId;
	public String itemName;
	
	public Item(int itemId,String itemName)
	{
		this.itemId=itemId;
		this.itemName=itemName;
		
	}
	public void display()
	{
		System.out.println("Item ID:"+itemId+"\n"+"Item Nmae :"+itemName);
	}

}

Customer Class Source code


public class Customer extends Human {
	public int id;
	public String name;
	Item item;
	
	public Customer(String scientificName,int id,String name,Item item)
	{
		super(scientificName);
		this.id=id;
		this.name=name;
		this.item=item;
		
	}
	public void display()
	{
		super.display();
		System.out.println("ID :"+id+"\n"+"Name:"+name);
		item.display();
	}
	public static void main(String[] args)
	{
		Item itm =new Item(1020,"GPU");
		Customer cmr = new Customer("graphics card",805,"Rahim",itm);
		
		cmr.display();
		
	}

}
Output

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Do You Want To Contact With me?

drop us a line and keep in touch