Похожие презентации:
Simple restaurant simulation - 2
1.
Simple RestaurantSimulation 2
C# Training Exercises
2.
OverviewGoals(максадхо)
Problem Domain(проблемахо)
Requirements(талаботхо)
Design Guidelines(дизайн)
3.
Goals(максадхо)Concepts in Visual C# Step by Step chapters 9, 10, 11, 12(истифодаи мавзуъхои 9, 10,
11, 12)
Basic inheritance(наслгири)
Arrays(массивхо)
Enumerations(шуморахо)
4.
Problem Domain: Restaurant RevisitedYour restaurant has needed some improvements(Ба ресторани шумо якчанд бехбудихо лозим)
Your first employee ( “Cook” ) has improved his memory and now makes no
mistakes(Коргари якуми шумо – ошпаз хотирааш мустахкам аст ва дигар ягон хатогихоро намекунад)
You have hired a second employee ( “Server” ) to obtain customer requests from
each table and serve the prepared food to the table(Шумо коргари дуюм – хамчун хизматгон ба
кор кабул кардед барои кабули дархост аз клиентхо ва бурда расонидани дархостхои тайёршуда)
Each table can seat up to 8 customers(Хар як мизи хурокхури максимум 8 нафар клиенро дарбар
мегирад)
This computer program will simulate:
Барномаи Шумо бояд чунин корхоро ичро карда тавонад
Obtaining a food request from each customer at a table(Кабули дархости хурок аз хар як клиен)
Submitting the entire table’s request at once to be prepared(Фиристодани хамаи дархостхои
Serving the requested food to each customer at the table(Пешниход ва ё бурда расонидани
клиентхо барои тайёр кардани хурок)
дархости хар як клиент)
5.
Requirements6.
Sample User InterfaceMy Restaurant
Menu
How many chicken? 0
How many egg?
3
Tea
Receive this request from a Customer
Send all Customer requests to the Cook
Egg Quality: 65
Serve prepared food to the Customers
Results
7.
Simulated Employee ActionsАмалхое, ки хизматгор ва ошпаз ичро карда метавонанд
Server
Cook
Receive Request from a single
Customer(Кабули дархост аз як клиент)
Send all requests to the
Cook(Фиристодани хаммаи дархостхо ба ошпаз)
Serve prepared food to
Customers(Овардани дархостхои клиентхо)
Submit Request for Food(Кабули
дархост аз хизматгор барои пухтан)
Prepare Food(Пухтани хурок)
These are the same actions that you
implemented in the previous
project(Хамаи ин амалхо монанди дорад бо проекти
якум)
8.
Server Action 1: Receive(Кабули дархост)The Server receives a single customer’s request(Хизматгор танхо дархости як нафарро кабул карда
метавонад)
The request contains(Дархост аз чунин кисмхо иборат аст:):
Quantity of chicken (may be 0, but no decimal values)(Микдори мург)
Quantity of egg(Микдори тухм)
Choice of drink(Намуди нушоки)
You should offer multiple drink choices that customers might enjoy(Шумо метавонед якчанд
нушокиро ба клиент пешниход кунед, ки ин аз хохиши Шумо вобаста аст)
One of the choices should be to request no drink at all(Клиент метавонад нушокиро дархост накунад,
дар ин холат NoDrink истифода карда мешавад)
Server stores the request until all customers at the table have made their requests
Up to 8 customers are allowed per table (Хар як мизи хурокхури максимум 8 нафар клиенро дарбар
мегирад)
9.
Server Action 2: Send(Фиристодани дархостхо)
Server sends the accumulated requests to the Cook(Хизматгор дархостхоро ба ошпаз
мефирсонад)
Invoke the Cook’s Submit action for Chicken, specifying quantity (Методи Submit() – и
Invoke the Cook’s Prepare action for Chicken(Методи Prepare() – и класи Cook барои пухтани
класи Cook барои кабули хаммаи мургхо чег зада шавад)
хаммаи мургхо чег зада шавад)
Invoke the Cook’s Submit action for Eggs, specifying quantity(Методи Submit() – и класи
Cook барои кабули хаммаи тухмхо чег зада шавад)
Invoke the Cook’s Prepare action for Egg (Методи Prepare() – и класи Cook барои пухтани
хаммаи тухмхо чег зада шавад)
Important: to make this project take less time, you may ignore any rotten eggs(Хаммаи
тухмхо сифати хуб дорад)
Server does not need to tell the Cook about the drinks,
because the Server pours the drinks himself.(Хизматгор ба ошпаз дар бораи нушоки ягончи
намепурсад)
10.
Server Action 3: Serve(Бурда расонидани дархостхо баклиентхо)
Server gives the prepared food to each customer(Хизматгор дархостхои тайёршударо ба
хар як клиент бурда мерасонад)
Make sure you have no leftover food.(Хаммаи дархостхои клиентхо бояд ки ба пурраги, бе
хатоги бурда расонида шавад)
We will simulate this with the results window, for example(Натича чунин мешавад):
Customer 0 is served 2 chicken, 1 egg, Tea
Customer 1 is served 1 chicken, 0 egg, Coca Cola
Customer 2 is served 0 chicken, 3 egg, no drink
Please enjoy your food!
11.
Design Guidelines12.
Refactor for Inheritance(Тагйирдихии кодхо барои истифодаи наслгири)
Notice that ChickenOrder and EggOrder classes that you created in previous
project have many similarities.(ChickenOrder ва EggOrder, ки дар проекти пешина сохта будед, ба
хамдигар монанди дорад)
You should refactor these classes to derive from a new base class(Шумо бояд ин
класхоро барои аз класи нави базави насл гирифтан тагйир дихед)
Consider the following:
What should be inherited? (methods, fields, constructors)(Фикр кунед, ки кадом методхо,
тагйирёбандахо ва конструкторхои клас бояд насл гирифта шавад)
How should it be inherited? (public, private, protected, virtual, override) (Фикр
кунед, ки кадом модифика бояд истифода шаванд)
13.
Refactor for Inheritance:Hierarchy
Order
ChickenOrder
EggOrder
14.
Refactor for Inheritance:base class ‘Order’
Order
Constructor( Quantity )
GetQuantity()
Cook()
SubtractQuantity()
15.
Refactor for Inheritance:derived class ‘ChickenOrder’
ChickenOrder
Constructor( Quantity )
CutUp()
Cook()
16.
Refactor for Inheritance:derived class ‘EggOrder’
EggOrder
Constructor( Quantity )
GetQuality()
Crack()
Discard()
Cook()
17.
Data Modeling of a Menu ItemOur restaurant currently offers the following menu items(Ресторан чунин менюхоро
пешниход мекунад:)
Chicken
Egg
Several types of drink
You should create a C# enumeration to represent the set of possible menu
items(Барои хар як меню шумора(C# enumeration) созед)
18.
Data Modeling of a Single RequestThe request from a single customer will include(Дархости як нафар мизоч аз чунин кисмхо иборат
аст):
Zero or more chicken
Zero or more egg
Zero or one specific drink
We could represent this with an array of menu item enumeration values(Барои
Example: A customer requests 2 chicken, 3 egg and tea(Намунаи нигохдории дархости мизоч
дар массив, ки дар он мизоч 2 мург, 3 тухм ва чой дархост кардааст):
нигохдории менюхо массиви типаш шумораи сохташударо истифода баред)
Chicken
Chicken
Egg
Egg
Egg
Tea
But how do we store the requests of all the customers at once?
(answer on next page – can you guess?)(сохтори массив дар слайди навбати оварда шудааст)
19.
Data Modeling of Requests for a TableYou should represent the entire set of requests as a jagged array(Шумо бояд
массиви сутуншакл – массиви массивхоро истифода баред)
Type is the menu item enumeration(Типи массив шумораи сохташуда барои нигохдории менюхо)
Dimension 0 is the customer(Ченаки 0 ин раками мизоч)
Dimension 1 is the menu item(Ченаки 1 ин намуди меню)
Example:
Customer 0
Chicken
Egg
Customer 1
Chicken
Chicken
Customer 2
Egg
Egg
Customer 3
Tea
Coca-Cola
Egg
Pepsi
20.
Design RestrictionsAvoid concepts that have not yet been introduced in the training.
Specifically, do not use(Мафхумхое, ки дар поён оварда шудааст, истифода набаред):
Collections
Abstract classes
Interfaces
Why these restrictions?
To give you practice with the concepts that have just been taught, rather than
alternate solutions you might already know.
Менеджмент