[go: up one dir, main page]

0% found this document useful (0 votes)
48 views6 pages

Fun Fair

A fun fair has several shooting galleries where guests can win prizes. The most successful guest at a shooting gallery is the one with the most valuable collection of prizes from that gallery. The value of a prize depends on both its type (ball, doll, teddy bear) and size (S, M, L, XL), with different point values assigned based on the matrix.

Uploaded by

canberk.arkose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views6 pages

Fun Fair

A fun fair has several shooting galleries where guests can win prizes. The most successful guest at a shooting gallery is the one with the most valuable collection of prizes from that gallery. The value of a prize depends on both its type (ball, doll, teddy bear) and size (S, M, L, XL), with different point values assigned based on the matrix.

Uploaded by

canberk.arkose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Fun fair

A fun fair has several shooting galleries. The guests of the fun fair may try to shoot
in any of them. Every successful shot means results in a prize for the guests. It is
known, which gallery a prize belonged before. A prize can be of 3 types: ball, doll,
or teddy bear. It can have different sizes, like S, M, L, or XL.
The value of the prize can be calculated as the following: a ball worths 1 point, a
doll worths 2 points, and a teddy bead worths 3 points. According to its size, the
point is multiplied by a given multiplier: the multiplier for size S is 1, for size M it is
2, for size L it is 3, and size XL means 4.
Find the most successful guest of a given shooting gallery. Most successful means
that that guest has the most valueable collection of prizes from that shooting
gallery.

Object-oriented programming 1
Fun fair if |guests|=0 then error endif
(. , elem) := MAX e∊guests e.Value(this)
return elem.name

Gallery
FunFair * + location : string
+ Present(p:Prize) p.gallery := this
+ Register(g:Guest) guests.Insert(g)
+ Best():string
* + gallery
visit
present
* - guests *
Guest Prize Size
+ name : string 0..1 nyer *
- prizes
+ Visit(g:Gallery) + Value() : int + Mult() : int
} {virtual}
+ Win(p:Prize) + Point() : int {virtual}
+ Result(g:Gallery) : int - size
c.Register(this)
return Point() ∙ size.Mult()
return ∑ e.Value() prizes.Insert(p)
e∊prizes
e.gallery = c

Object-oriented programming 4
Fun fair
Template method Every method is
query
return Point() ∙ size.Mult()
Strategy

Prize * Size
+ Value() : int { virtual } + size
+ Mult():int { virtual }
+ Point() : int { virtual }

<<singleton>> <<singleton>>
S <<singleton>> <<singleton>> XL
M L
+ Mult() : int + Mult() : int
{ override } + Mult() : int + Mult() : int { override }
return 1 { override } { override }
return 4
return 2 return 3
Ball Doll Teddy

+ Point() : int + Point() : int + Point() : int Singleton


{ override } { override } { override }
return 1 return 2 return 3
Object-oriented programming 5
Fun fair
Let us suppose that the value calculation for a prize is not so easy: it depends on
the size and the type in the following way:

S M L XL
Ball 1 1 1 3
Doll 1 1 2 2
Teddy 1 2 3 4

Object-oriented programming 6
Fun fair Size

+ Point(Ball):int { virtual } Every method is


+ Point(Doll):int { virtual } query
+ Point(Teddy):int { virtual }

return 1 return 3

S return 1 XL return 2
+ Point(Ball):int { override } + Point(Ball):int { override }
+ Point(Doll):int {override } + Point(Doll):int {override }
+ Point(Teddy):int {override } + Point(Teddy):int {override }
return 1 return 4
return 1 return 1

M return 1 L return 2

+ Point(Ball):int { override } + Point(Ball):int { override }


+ Point(Doll):int {override } + Point(Doll):int {override }
+ Point(Teddy):int {override } + Point(Teddy):int {override }
return 2 return 3
Object-oriented programming 7
Fun fair
Visitor

Prize * Size
+ Value() : int { virtual, query } + size
+ Point(Ball):int { virtual }
+ Point(Doll):int { virtual }
+ Point(Teddy):int { virtual }

S M L XL

Ball Doll Teddy

+ Value():int {override,query} + Value():int {override,query} + Value():int {override,query}

return size.Point(this) return size.Point(this) return size.Point(this)

Object-oriented programming 8

You might also like