Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card...
-
Upload
benjamin-greene -
Category
Documents
-
view
213 -
download
0
Transcript of Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card...
![Page 1: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/1.jpg)
Programming Games
Credit cards. Forms.Homework: Catch up: dice game. Produce
your own credit card application or something else making use of a form with computations.
![Page 2: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/2.jpg)
Formulas
• Mathematical expressions are combinations of operators and terms– examples of operators: +, -, *, /, ==, ===, !=, &&, …– examples of terms: variable name, constant
• Programming languages have features for expressing mathematical formulasdistance = velocity x time
Code, assume distance, velocity, time all variablesdistance = velocity * time;
multiplication
=== checks for datatype & value
![Page 3: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/3.jpg)
Well-formed expression
• Show a NOT well-formed expression
A = B *
toss(a, b, c
![Page 4: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/4.jpg)
Function expressing formula
function distance (velocity, time) { return velocity * time;}Give me velocity and time and I'll [the
function] will return the distance.
The function header indicates the [incoming] parameters (aka arguments). NOTE: in many languages, the function header also indicates the datatype of each parameter and the datatype of the returned value. This makes it possible to check that the programmer is NOT using the functions incorrectly…at least as far as datatype.
![Page 5: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/5.jpg)
Expressions
• An expression is a combination of operators and terms, with the terms being variables or literals (for example, numbers)
• Examples:10 * scorebill + bill*.08now <= then + duration(day != "Saturday") ? 2200 : 2400xpos > xborder(xpos > leftwall) && (xpos <rightwall)
Note: && is logical AND operator WHICH does NOT evaluate the second term if the first is false.(gpa >3.0) || (credits >90)
Note: || is logical OR operator which does NOT evaluate the second term if the first one is true.
![Page 6: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/6.jpg)
Temperature conversion
Tempfahrenheit = Tempcentigrade*(9/5)+32;
Check by putting in points
for boiling:
212 Fahrenheit and 100 Centigrade
For freezing
32 Fahrenheit and 0 Centigrade
What is formula for… the other direction?
![Page 7: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/7.jpg)
Interlude: Computer jargon• A bit is a 1 or 0. Abbreviation b• A byte is made up of 8 bits. Abbreviation B.
– ASCII is a system for representing symbols, such as the letters, in 8 bits, which is 1 byte.
– Unicode uses 16 bits.
• How many different patterns of 1s and 0s can be held in 4 bits? 8 bits? 16 bits?– Hint: start with 1 bit and keep going and notice
the pattern.
![Page 8: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/8.jpg)
Caution• Recall: Programming systems may store whole
numbers (0, 1, 2, -10, etc.) differently than numbers with fractions (0.5, 10.23, -2.3333333, etc.)
• Need to make sure that none of the intermediate steps are truncated to whole numbers!– One approach: write 9.0 and 5.0 and 32.0– Note: problems occurs with the division, not
multiplication or addition
• Extra credit opportunity: what does JavaScript do?
![Page 9: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/9.jpg)
JavaScript program
function convertToFahrenheit(T) {var ans;ans = (9.0/5.0) * T + 32.0;return ans;}
ORfunction convertToFahrenheit(T) {
return (9.0/5.0) * T + 32.0;}
![Page 10: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/10.jpg)
Precedence
• Many programming courses start off with rules of precedencea*b+cIs evaluated as (a*b)+c. The multiplication is
done first
The alternative is a* (b+c)
• Recommendation: put in parentheses!
• MAYBE: avoid long statements—use multiple lines
![Page 11: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/11.jpg)
Conditionals
• Suppose a formula (for ticket price or score or …) involves a conditional test:– On Tuesdays, drinks are half priceLogic: if it is Tuesday, dcost = .5*dcost;
• Implementation: use if statement– Alternative: conditional operator. Show later.
• But how do we know if it is Tuesday?• Implementation: use Date
– Remember from first HTML example!
![Page 12: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/12.jpg)
Date code• Suppose policy of half-price on Tuesdays
today = new Date();
dayofweek = today.getDay();
//encoding is 0 for Sunday, 1 for Mon.,
// 2 for Tuesday
if (dayofweek==2) {
dcost = .5 * dcost;
}
![Page 13: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/13.jpg)
Conditional operator
• Operator with 3 operands condition ? value_if_true : value_if_false
…
dcost = (dayofweek==2) ? (.5*dcost) : dcost;
Comfortable_with_conditional ? Use_It : if_statement
![Page 14: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/14.jpg)
A man walks into a bar…
See also: http://faculty.purchase.edu/jeanine.meyer/creditcard.html
Notes: http://faculty.purchase.edu/jeanine.meyer/credit.doc
![Page 15: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/15.jpg)
Credit cards!!!!
• Calculation (as indicated by code)balance = old_balance + purchases
Subtract the payment:balance = balance – payment
Compute interest
Divide ANNUAL interest by 12.
REMEMBER DECIMAL POINT
balance = balance + (balance * interest)
Add fee if required: balance = balance + fee
![Page 16: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/16.jpg)
Estimating
• 24% ANNUAL interest is 2% per month– 24/12 is 2!
• What is 2% of $50?– 2% of 100 is 2. So…2% of 50 would be 1– What is 10% of 50? 5, so 2% would be less
than that
• 15% ANNUAL interest. Monthly would be…more than 1 less than 2 (1.25)
![Page 17: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/17.jpg)
Compounding• The interest is added to what you owe. • The new balance is what you haven't paid plus
the interest on what you haven't paid.• Next month, you will be paying interest on the
interest.• This doesn't include fees for not paying the
minimum • My program does not do compounding on a
daily basis. Actual rules mean you pay more!• NOTE: it still is a free loan if you pay off balance.
– There are charges to merchants.
![Page 18: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/18.jpg)
Compounding
• is your friend, when you are saving (or investing)– You earn interest and then interest on the
interest.
• is your enemy if you owe money
• Interests are very low now, but they (probably) will rise!
![Page 19: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/19.jpg)
Writing on image
• http://faculty.purchase.edu/jeanine.meyer/html5/addmessage.html
• Notice different types of input– Radio buttons– Range– Color– html
![Page 20: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/20.jpg)
Braiding
• http://faculty.purchase.edu/jeanine.meyer/braidloosetightshake.html
• Again, notice different forms of input
• Aside: uses 2 ½ D technique of small canvas elements (more on this later)
![Page 21: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/21.jpg)
What went wrong & why?
<html><head><title>test</title><script>
function addone () {
document.f.score.value = 1+document.f.score.value;
return false; }
</script></head><body>
<form name="f" onSubmit="return addone()">
Score: <input type="number" value="0" name="score"/>
<br/>
<input type="submit" value="Add 1"/></form></body></html>
![Page 22: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/22.jpg)
Number theory examples
• http://faculty.purchase.edu/jeanine.meyer/numbertheory/
![Page 23: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/23.jpg)
Hints• For slide show (and any other application
(program) with media,) you need to upload the image files along with the html file(s)
• One second for me is– One Mississippi
• Think about your player/customer/user…– What is expectation on controls, aka affordances
![Page 24: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/24.jpg)
Recap today• “Same deal” meant owe interest on everything
owed. This included (original) interest + fee.• JavaScript forms support text input plus
URL,color, radio, other– Look it up!
• JavaScript also provides way to get input from user/player/customer clicking on canvas and code determines position– Code did a rotation for writing text on canvas.
![Page 25: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/25.jpg)
Homework
• Take the credit card application and make it your own– add graphics?– change form?– ?
• OR create another application making use of input from a form and doing calculations
![Page 26: Programming Games Credit cards. Forms. Homework: Catch up: dice game. Produce your own credit card application or something else making use of a form with.](https://reader036.fdocuments.in/reader036/viewer/2022081520/5697bf841a28abf838c86a9a/html5/thumbnails/26.jpg)
Recap• Catchup: if behind, do dice game and slide
show. We will start on virtual something next week.
• Keep up with taking notes, doing research– Form input– How to get time of day from Date object– JavaScript way of storing numbers– Ideas for projects
• Get help: office hours, Einstein’s Corner