lecture 1 part a elementary programming - development processjackie/teaching/lectures/2021... ·...

46
Lecture 1 Part A Elementary Programming - Development Process

Upload: others

Post on 01-Feb-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

- Classes & Methods - Methods * containing no print statements * return statements
- Expected vs. Actual Values - Methods * calling methods from model * containing no print statements * assertions
- main method * calling methods from model * containing print statements * containg no return statements
1
3. output expected
I .
D l l l l
-
D

-
00
Error at Compile Time: Type Errors (2)
# -
no compile-time error⇒
I .
I. compiles 2. terminates without crashing 3 . output is wrongs .
Document Your Code
Operator, Operands, Operation
- An operation consists of an operator and one or more operands. - An operator has one or more applicable operands. - An operation produces a values of certain type.
3 * 7
- (24 / 4)
x < y
! (x >= y)
[ numerical operation >
* a.ws ⇐ gain
"" '
Case I → quotient. kziyytwojntegersxsy Tmthqzgd? I - yx-sxhsytcxg.ge#egged.gnefloaeag-P-mt
Case 2 precise result
Data Type Declarations
once yenta:&.net:4#....ti..en%daaseaf dp= 3.µ ,
( mandatory)
of variable ( optional
yay . utfseogeeassdgmei Fats .
'
Variable: Initialization vs. Re-Assignments
* Counter value is 2
Fix 1: Only Keep the 1st Declaration
Fix 2: Declare a New Variable
O .
x
Ginter
a.io?::h.oQiehEn
µ declaration
× P f -
D are type-correct.
"Hello " * "world"
"Hello " + 3 + 2 * 2
Automatic Coercion: int to double yes -5 3-0
,-494¥ → double
int value1 = 3.1415926; int value4 = (int) 3.1415926;
double value2 = 3.1415926; int value3 = value2; int value5 = (int) value2;
I .
0.50.
.
.
di =
I = - '¥79
.. "
Augmented Assignments Fino so .
D
I -1=1
Exercise: Preceeding vs Following ++
-
K -- TEJ 's
→ perform assign.EE
Console Application: With User Inputs vs Without
Without User Input
Without User Input
Test: 500 seconds
Exercise: Modify the program so that it will display hours if necessary. e.g., 7945 seconds -> 2 hours, 2 minutes, 9 seconds
% IT 500
-0 D-- D
' assignment target
' a '
refute mm
type . q
print (s1); print (s2);
println (s1); println (s2);