Search code examples
javainterfaceumlabstract-classclass-diagram

Deriving abstract classes and interface from UML class diagram


enter image description here

enter image description here

I have to implement the concrete classes, Pizza and Lasagne and the interface Food in Java and I am stucked at how to calculate the price using the CalculatePrice() method without having a Price variable in the class diagram because using only type and size, one cannot calculate the price of the pizza as per the table.


Solution

  • since price variable is not available, you will have to write your own logic on how to calculate price based on type and size.

    For Lasagne, you dont have size, so only type matters here. Different types --> different prices.

    For Pizza, based on type, and size (small, medium, large, extra large) you can write code for calculate price.

    Show your creativity here.