基督城理工学院信息和通信技术专业留学生essay指导:Vending Machine
Introduction:
This assignment is all about planning a complex algorithm.
Once you have analyzed existing data structures and methods you will plan an algorithm in Scratch, test it and then you will translate Scratch code into a working Jade program which runs against provided unit tests.
In this assessment you are going to be designing and creating code to implement business rules of medium complexity. There is no code you can copy. You are going to have to work out for yourself how the code is to be structured.
Some revision of theory and Jade syntax will be useful to give you the theoretical skills to complete this assignment successfully.
You need to re-read:
- McConnell Chapter 14 and complete the Using Conditionals Worksheet
- McConnell Chapter 15 and complete the Controlling Loops Worksheet
- McConnell in chapter 4 of Code complete which discusses “Steps in Building a Routine’.
- McConnell in chapter 9 on “The Pseudocode Programming Process”.
这是关于一个复杂任务规划算法。
当你分析现有的数据结构和方法,你将计划在抓一个算法,测试它,然后你将从代码到一个工作的程序运行对提供的单元测试。
在这个评估你要创建的代码来实现复杂的业务规则设计。没有代码可以复制。你必须去解决自己的代码是如何被结构化。
一些修正理论和玉语法将给你完成这个任务成功理论有用的技巧。
你需要重新阅读:
麦康奈尔14章完成使用条件表
麦康奈尔15章和完整的控制回路的工作表
麦康奈尔在4章论述了建设中的“代码完成常规步骤。
在9章麦康奈尔对“伪代码编程过程”。
The marking guide rewards following a McConnell-like approach.
This assignment combines both the 10% Dynamic Modeling assignment and the 15% Programming Assignment.
SUB-TASKS:
NOTE: There are different marks weighting and grading criteria for each part.
The following table shows the grade weighting of each "deliverable" as a % of the total grade for this assignment.
#p#分页标题#e#5% 1.Planning[compulsory]
5% 2.Commenting existing methods [compulsory]
5% 3.Code prerequisites worksheet [compulsory]
10% 4.Object Diagram[compulsory]
20% 5.Creating an Algorithm in Scratch [compulsory]
5% 6.Write Use Case [compulsory]
5% 7.Decomposition[optional]
10% 8.Converting Scratch to JadeScript [optional]
30% 9.Acceptance Testing[optional]
30% 10.Enhanced Aesthetics[optional]
50% 11.Cope with requirements changes[optional]
Note that these add up to more than 100%. If you get more than 100% according to these weightings, you will be awarded 100% for the assignment.
The following sections discuss the requirements and deliverables for each sub-task of the assignment.
1. PLANNING 5%(COMPULSORY)
Create a work plan which shows when you will devote at least twenty-five hours to this assessment. Your plan must allot at least four separate sessions to this assignment. A course tutor must sign off that you have followed your plan for you to receive these marks.
30 23-Jul 1 Semester Two Commences Monday 23 July #p#分页标题#e#
31 30-Jul 2
32 6-Aug 3
33 13-Aug 4
34 20-Aug 5
35 27-Aug 6
36 3-Sep 7 Assignment 1 due on 7th September 2012 at 17:00
Maintain a time log with 15 minute intervals while working on this assignment. For each time 15 minute interval show which of the assignment tasks you spent most of your time working on.
Create a pie-chart showing how much time you spent on each section of this assignment.
Write at least 500 words on the topic: ‘Where does the time go when you are programming? Why?” This can be in a ‘notes’ format.#p#分页标题#e#
HAND IN:
• The marking sheet with dates and a staff signature from the end of this document.
• A print out of the time log
• A print out of the pie chart
• The 500 word short notes / essay.
2. COMMENTS OF EXISTING METHODS 5%(COMPULSORY)
The method you are coding the algorithm for is
VendingMachine::giveChange( selectedProductRack : ProductRackio ;
deposit : Integer ) updating;
You will need to understand and use some of the methods that have been provided. To help with this write comments in each of the following method at the point indicated (1/2 mark per commented method)
HINT: look for and replace ALL the???
countChange( coinValue : Integer): Integer protected;
findProductRackByCost( desiredCost : Integer ): ProductRack updating;
getNextBestRefund( refundValue : Integer ): ChangeHolder protected;
giveCoin(coinValue : Integer ) updating, protected;
giveCoins( coinValue : Integer; coinsCount : Integer ) updating, protected;
hasCoin( coinValue : Integer): Boolean protected;
sumCoins( coinValue : Integer): Integer protected;
getCoinDenominationsCount(): Integer;
getProductCost(): Integer;
giveCoinByPosition( position : Integer ) updating, protected;
3. CODE PREREQUISITES WORKSHEET 5%(COMPULSORY)
Think about what the routine should do and get answers to the following topics. (See McConnell Chapter 7)
Define the problem
Information the routine will hide
Inputs to the routine
Outputs from the routine
Pre-conditions
#p#分页标题#e#Post-conditions
Name the Routine DONE FOR YOU
Decide how to test the routine DONE FOR YOU IN JADE TEST CASE
Research functionality available in standard libraries
Think about error handling
Think about efficiency
Research algorithms& data types
想想什么样的程序应该做的,并得到以下主题的答案。 (麦康奈尔第7章)
定义问题
信息程序将隐藏
输入的例行
输出从常规
先决条件
发布条件
命名为你做的常规
决定如何测试程序为你做玉皇测试用例
研究功能可在标准库
想想错误处理
想想效率
研究算法和数据类型
4. OBJECT DIAGRAM 10%(COMPULSORY)
(1) Object diagram of the initial setup of a Jadescript unit test (10 marks)
The first thing you have to do is get your head around how the existing data is structured. To do this you will ‘reverse engineer’ some of the design and planning work which was done before the code was first created.
The class diagram of the setup is as follows:
You have to draw an Object Diagram of the objects created by the code in Jadescript::testChangexx().(You will each be given your own numbered test to document)
To see what has been created by this method, in the JadesScript method add a line which says
vendingMachine.inspectModal();
just before the lines which say
write "Before";
displayAll();
NOTE: Hand drawing this diagram is acceptable.
Your diagram must include:
all Changeholders (referenced twice)
all coin instances
all product racks
selected product rack
all product instances
coinEjector
deposited coins holder
all relationships (with navigability arrows)
values of unique attributes shown
Here are some of rules of the system…
THE PRODUCT VENDING MACHINE HOLDS PRODUCTS AND DISPENSES THESE, ALONG WITH APPROPRIATE CHANGE, WHEN ENOUGH MONEY IS RECEIVED AND A PRODUCT TYPE IS SELECTED.#p#分页标题#e#
1. Product is held in dispensing racks. One type of product is held per rack.
2. The machine has an ID code for each product dispensing rack.
3. The machine can sense whether a product dispensing rack is empty or not.
4. The machine keeps a count of the number of products in each dispensing rack.
5. The machine increases the count of the number of products every time a product is loaded.
6. The machine decreases the count of the number of products as a product is dispensed.
7. There is a display for each dispensing rack which holds product. It is lit up if there are still products in the rack.
8. The price of product in each different rack can vary. The price of the product in one rack remains the same.
9. There is a slot which accepts by default 5, 10, .20, .50, $1.00 and $2.00 coins. (The slot can be configured to accept other denominations of coins.)
10. Whenever coins are placed in the machine, the total amount entered in this transaction is updated and displayed.
11. A selection button can be pressed to release a product if the total entered equals of exceeds the price of the product.
12. Each rack of products corresponds to a selection button.
13. If a product dispensing rack is empty, then the corresponding selection button is disabled.
14. Coins are stored internally in a coin dispensing rack. There is one rack for each denominator of coins.
15. The vending machine keeps a count of the total value of coins inserted during a transaction. This count is zeroed every time an enabled selection button is pressed and a product is dispensed.
16. Money put into the vending machine will be returned if no valid product selection button is pushed and a refund button is pushed.
17. The correct amount of change will be automatically be dispensed if a product is selected/delivered and more than the correct price has been inserted.#p#分页标题#e#
18. It is possible to preset a minimum amount of coins in each coin dispensing rack.
19. The machine switches itself “Out Of Order” when it has less than the preset minimum amount of coins in any of the coin dispensing racks.
20. The machine switches itself “Out Of Order” when it has no products in any can dispensing rack.
21. The machine can be electronically queried as to the state of its can dispensing and coin dispensing racks. It reports the current total of products/coins in each rack.
5. DEFINING AN ALGORITHM 20%(COMPULSORY)
TASK: Write in the provided SCRATCH program an algorithm which will calculate the coins needed to provide change when a user of a vending machine purchases a product.
Make sure it works for the following scenarios:
NOTE: Assume the system only has 50 cent and 10 cent coins available for giving change.
1. The user inserts a $2.00 coin and selects a product worth $2.00. The system vends the product and returns no change.
2. The user inserts a $2.00 coin and selects a product worth $1.50. The system vends the product and returns a .50 cent coin as change.
3. The user inserts a $2.00 coin and selects a product worth $1.80. The system vends the product and returns two 10 cent coins as change.
4. The user inserts a $2.00 coin and selects a product worth $1.40. The system vends the product and returns a 10 cent coin and a 50 cent coin as change.
5. The user inserts a $2.00 coin and selects a product worth $.80. The system vends the product and returns two 50 cent coins and two 10 cent coins as change.
VENDING MACHINE BUSINESS RULES FOR GIVING CHANGE
• The product vending machine holds products and dispenses these, along with appropriate change, when enough money is received and a product type is selected.
• All internal calculations are conducted in whole integer cent values.
• The customer must never be short changed.
• Change will always be given in coins which are of the largest valued coin that is equal to or less than the amount which needs to be refunded and the machine actually still has some coins of that value left.#p#分页标题#e#
• Availability of coins for refunding is finite. The system can run out of a particular denomination of coin for using as refunds. Availability of a particular value of coin for refund needs to be checked.
• Only valid coins are accepted as deposits. By the time the change giving algorithm is called, all deposited coins will be valid.
• The change giving algorithm will only be called when the user has selected a product of a know value.
• The system adds up the total amount of deposited coins before calling the change giving algorithm.
• The change giving algorithm should NOT give change if not enough money has been deposited.
• The Vending Machine has to be able to cope with different currencies and coin denominations.
In your Scratch code, when you need information about the state of the system you should just ask for the required information. Assume that the answers provided will always be accurate. e.g.
obtain amountDeposited
In your Scratch code, when you need to indicate that a system operation should take place, just show that it does. e.g.
show 'The product is vended'
You will receive marks according to your SCRATCH QUALITY:
sensible variable names
correct use of selection blacks
correct use of iteration blocks
commenting
decomposition of the algorithm (start, middle, end)
works for test case 1
works for test case 2
works for test case 3
works for test case 4
works for test case 5
HAND IN: A copy of the scratch file
OR hand in the verified marking sheet from the end of this document.
6. WRITE USE CASE 5%(COMPULSORY)
Write use case for: vend product
A brief description: the purpose of the use case in a few lines
A statement of the pre-conditions on which the use case depends
A believable main flow (the normal, basic, sequence of transactions)
Several (at least 1) alternative flows
Several (at least 1) exception flows
How and when the use case starts and ends#p#分页标题#e#
When the use case interacts with the actors
What information is exchanged between an actor and the use case
A statement of the post-conditions at the end of the use case
HAND IN: Printout of written use case(s) or upload them on Moodle
7. DECOMPOSITION 5%
Everywhere you have blocks of input or output, write a procedure or function to do the same processing as happens in the block of code and pass and return parameters as necessary.
TASK: Rewrite JadeScript::TestVendingAlgorithm so that it calls ‘helper’ methods to do input or output.
All read and write statements should be replaced by method calls which return a value or which take parameters.
eg
testVendingAlgorithm() updating;
vars
amountDeposited : Integer;
begin
amountDeposited := getAmountDeposited();
// there will be more code here!
end;
getAmountDeposited(): Integer;
vars
amountDeposited : Integer;
begin
// obtain amountDeposited
write 'Enter amount deposited';
read amountDeposited;
write amountDeposited;
return amountDeposited;
end;
HAND IN:
A copy of ALL your Jadescript methods
OR hand in the verified marking sheet from the end of this document.
8. CONVERTING SCRATCH TO JADESCRIPT 10%
TASK: Establish the soundness of your algorithm by coding it in JadeScript.
• Create a Jadescript method named ‘testVendingAlgorithm’.
• Paste or type your scratch algorithm into the JadeScript method as single line comments
• Define all necessary variables
• Define all necessary constants
• Code your algorithm in Jadescript
• Use read statements at the top of the code to get values for the product price and the amount inserted.
• Use write statements to indicate that a product has been vended and that change has been returned.
eg#p#分页标题#e#
testVendingAlgorithm() updating;
vars
amountDeposited : Integer;
begin
// obtain amountDeposited
write 'Enter amount deposited';
read amountDeposited;
write amountDeposited;
// there will be more code here!
end;
Your code will be inspected for the correct usage and style.
If you are in doubt as to what is "quality" usage of the feature then ASK!
For those of you despairing of having a working code, don't worry. You can still score full marks in this section with only some of your code working.
You will be graded on a marking scale of
0 = no evidence of usage
1 = adequate but some defects
2 = correct good quality usage
used appropriate naming conventions for variables
provided scratch comments in code
appropriate indenting of scratch comments in code
good use of branching
good use of looping
good use of white space within lines
good use of white space lines to separate code blocks
good use of indentation of Jade code
split long lines at appropriate points
good use of parentheses
HAND IN:
a copy of your Jadescript::TestVendingAlgorithm() method
OR hand in the verified marking sheet from the end of this document.
9. ACCEPTANCE TESTING 30%
Move yourJadescript code into the appropriate place in the Vending Machine schema.
Debug it as necessary.
There are tests available as Jadescript methods. How many of these tests work correctly with your code?
HAND IN:
Print all your code in your schema and get a digital copy of both schema file s to the lecturer
OR hand in the verified marking sheet from the end of this document.
10. ENHANCED AESTHETICS 30%
Make the application prettier!
Add
• images of coins
• images of products
• drag drop of coins
• animated displays of products being vended
• sound effects
#p#分页标题#e#
• a way of viewing (and hiding) the insides of the vending machine
For each of these effects you will get up to 2 marks per effect.
eg
if you provide 10 different sound effects
AND
the code to make them work in the game than you can get 10*2 = 20 marks.
You can negotiate other effects with the course lecturer.
Things which could also be improved include different sized buttons, screen colors, lack of a menu, no keyboard shortcuts, font sizes, control sizes. (You can add to this list at lot!) You would get up to TWO marks for fixing ALL occurrences of a minor aesthetic defect eg changing the fonts on ALL Buttons, not TWO mark per Button.
Whether this is worth one or two marks will depend on whether it is something done completely in the Painter (1 mark) or whether it also requires code (2 marks).
Confirm with the course lecturer how many marks an effect is worth and whether you get the marks for doing ALL of an effect or for EACH of an effect.
11. CHANGING REQUIREMENTS 50%
Make the code work with Canadian currency.
Rewrite new versions of all the unit tests so they use Canadian currency.
MARKING GUIDE BCSE102
ASSIGNMENT #1
Name: __________________________ Grade ____ / 100= ____ / 25%
5% PLANNING
Work plan followed on Date __________Signature ________________
Work plan followed on Date __________Signature ________________
Work plan followed on Date __________Signature ________________
Work plan followed on Date __________Signature ________________
Analyzed Time Log
5% COMMENTING
Comments
5% CODE PREREQUISITES
10% OBJECT DIAGRAM
20% CREATING ALGORITHM IN SCRATCH
sensible variable names
correct use of selection blacks
correct use of iteration blocks
commenting
decomposition of the algorithm (start, middle, end)
works for test case 1
works for test case 2
works for test case 3
works for test case 4
works for test case 5
5% WRITE USE CASE
#p#分页标题#e#TASK 1 Vend Product
5% FUNCTIONAL DECOMPOSITION
10% CONVERTING PSEUDOCODE TO JADESCRIPT
used appropriate naming conventions for variables
provided Pseudocode comments in code
appropriate indenting of Pseudocode comments in code
good use of branching
good use of looping
good use of white space within lines
good use of white space lines to separate code blocks
good use of indentation of Jade code
split long lines at appropriate points
good use of parentheses
30% ACCEPTENCE TESTING
I
30% ENHANCED AESTHETICS (something pretty)
I
50% COPE WITH REQUIREMENTS CHANGES
I
I