Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an uml diagramm package decorator trait Pizza: def diameter: Int def price: BigDecimal class Margherita extends Pizza: override def diameter: Int = 2 8

Write an uml diagramm
package decorator
trait Pizza:
def diameter: Int
def price: BigDecimal
class Margherita extends Pizza:
override def diameter: Int =28
override def price: BigDecimal =9
class Funghi extends Margherita:
override def price: BigDecimal =10
class Verdura extends Margherita:
override def price: BigDecimal =11.5
@main def Pizzashop(): Unit =
// pizza Verdura with extra cheese
val p1: Pizza = new ExtraCheese(new Verdura)
// pizza Funghi family size with vegan cheese
val p2: Pizza = new VeganCheese(new FamilyPizza(new Funghi))
println(s"Price of a pizza verdura with extra cheese is ${p1.price}")
println(s"Price of a pizza funghi family size with vegan cheese is ${p2.price}")
trait PizzaDecorator extends Pizza {
protected val pizza: Pizza
}
class ExtraCheese(val pizza: Pizza) extends PizzaDecorator {
override def diameter: Int = pizza.diameter
override def price: BigDecimal = pizza.price +2
}
class VeganCheese(val pizza: Pizza) extends PizzaDecorator {
override def diameter: Int = pizza.diameter
override def price: BigDecimal = pizza.price +1.5
}
class ExtraOnions(val pizza: Pizza) extends PizzaDecorator {
override def diameter: Int = pizza.diameter
override def price: BigDecimal = pizza.price +1
}
class FamilyPizza(val pizza: Pizza) extends PizzaDecorator {
override def diameter: Int =42
override def price: BigDecimal = pizza.price *2
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

What is the expected dollar cost of the forward hedge? L012

Answered: 1 week ago