+ All Categories
Home > Documents > Object Oriented Programmingjackie/teaching/tutorials... · 2021. 1. 29. · Working over Remote...

Object Oriented Programmingjackie/teaching/tutorials... · 2021. 1. 29. · Working over Remote...

Date post: 04-Feb-2021
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
78
Tutorial on ( EE 1022 - WH ) Object - Oriented Programming in Java
Transcript
EECS1022 Programming for Mobile Computing (Winter 2021)
Java Tutorials - Week 1
Work Environment + Software Management
* Create an EECS account: https://webapp.eecs.yorku.ca/activ8 * Remote labs: https://remotelab.eecs.yorku.ca/ * Eclipse available * Github commands available via a terminal * Clone a copy of repository here
+ Your Own Machine * Download the latest Eclipse: https://www.eclipse.org/downloads/ * Github desktop: https://desktop.github.com/ * Clone a copy of repository here

Gish add Commiteclipse
Local push RemoteLabCeithudebskwp .
Working over Remote Labs - Do not invoke the eclipse via the GUI icon! (which invokes Version 4.12) - On a terminal, type eclipse4.16 & - Do not type eclipse (which also invokes Version 4.12) - Before you log out and all data get lost, always commit and push your work back to Github!!
If You Want Extra Practice:
https://www.eecs.yorku.ca/~jackie/teaching/tutorials/index.html#java_from_scratch
→ a
ab ab
using input parameters 3 . return resale
& local var .
-
. JunkTe call uneckty methods
compute and ( manual ) (automated) .
Print values -6 console . compare return values against the expected values
console_apps
model
junit_tests
use
use
- Classes & Methods - Methods * containing no print statements * return statements
- -

Java Tutorials - Week 2
Arithmetic Sequence
- First Term (FT) - Common Difference (d) - Number of Terms - Sum
→ * i.
terms:€ O
1st : FT
F" 2nd : FT TED I*TtCH4f*d 3rd : IT tzd la Lo la 4th : FT t 3d Z z
5th : FT t→d 15+20=350 .
→ t# of terms - I
use
I N p return
use Y
Java Tutorials - Week 3
Single If-Stmt with Overlapping Conditions
50 55 60 65 70 75 80 90
Correct Test Value: marks = 63

50 55 60 65 70 75 80 90
incorrect Test Value: marks = 63
O9-f-stn-SI.mx" . # ''tht
50 55 60 65 70 75 80 90
Correct Test Value: marks = 63
63
×
-
ly →

50 55 60 65 70 75 80 90
Correct Test Value: marks = 63

/ M
EI:
an
| . 9263
Test Value: marks = 93 marks = 86 marks = 67 marks = 52
Correct

-4→e - do → Ig
-
-
"''
Nested If-Stmts
Test Value: marks = 93 marks = 86 marks = 67 marks = 52
Correctboss! → -
D B D O o D • •
-
Test Value: marks = 93 marks = 86 marks = 67 marks = 52
Correct ⇒⇒FESTER at D I
=¥ a 0 ⇒
67
⇒¥÷I
µ, " #
'e : Eto""
Java Tutorials - Week 4
for-Loop Syntaxyaeud-EYoieddarirgalfuthegupdceetheaubneq.eesure °
"
for-Loop: Tracing
→ I =
0
I is 3
O 0<5 It . # I P'"TT T is 4 Itt
I 1<5 It .
#2 P'THT Itt
- Itt
- Ttt
' Ttt
£9.97! ma
¢
while-Loop Syntax
.
Console
= O 0<5 It
. # I then
.
(tt
. #4 PETE,
T TS 2 c- type t 's
I is 3 c-
=
I 0
D
parameters .
→ Tesukiesylej . → - I A
tem -
Java Tutorials - Week 5
Tracing: Calculation of Indefinite Number of Assignments
Test Inputs: weight = 10 marks = 44 Y weight = 15 marks = 54 Y weight = 20 marks = 64 No
.
Tracing: Calculation of Indefinite Number of Assignments



Hint . Trade .
Indexing of an Array: Initializer
int[] ns = {10, 20, 30}; ns[0] = 23; ns[1] = 46; ns[2] = 69;
Address Calculation - base address - offset unit
Computer Memory
arrant integers
D nsa] :⇒ base -15*2 .
Indexing of an Array: New Object
Address Calculation - base address - offset unit
Computer Memoryint[] ns = new int[3]; ns[0] = 23; ns[1] = 46; ns[2] = 69;
ns == risto] ×
:
I, - '
⇒ 'e¥m¥¥E4.
EEE *
25 9 14
× aput → MM
⇒ input e- -
EECS1022 Programming for Mobile Computing (Winter 2021)
Java Tutorials - Week 6
Computer MemoryVisualization: Creating Objects Template Definition
Instance Creation
42321525 18796810%9 " :
member objects ' bald. 0.0×100.0
n . hell
yqame structure
w . o.O
12346 'b '
.
Mutator
attributes.
Visualization: Calling Methods Member
f -
. -
Java Tutorials - Week 7
Aliasing, Reference-Typed, Single-Valued Attributes
Reference Aliasing: Copying Address
'
the same co .
assettmecakn [ 9¥72
alan mark copy addressed stored in alanover to mark .
Reference Aliasing: Copying Addressuntying (
Member id
Member id
name
Trainer
mark - trainer -_ 7 ' 'Jared "
-
C '
Reference-Typed Attributes: Single-Valued vs. Multi-Valued
public class Member { /* single-valued */ private Trainer trainer; /* multi-valued */ private Facility[] facilities; }
Member trainer facilities
, i
p 4¥ where each index of the array stores the address of somefzz§f#f¢$Facility object u v v
fl→
Java Tutorials - Week 8
Aliasing, Reference-Typed, Multi-Valued Attributes
Keyong y '
n¥*h*ngi¥una"
7 . I
Reference-Typed, Multi-Valued Attributes getPaymentDue
Facility name price units
Facility name price units
Facility name price units
“Spinning Class” “Gym” “Locker”
⇐oheeyon.fac-dities-I.gl#ethe ~ tf¥4 s + C- o
. 4.0 I null null null
¥: '.IE#:nttIitiieEisEagegi7.*cx.' 144 M v u v
ft j j j Do finishing'm * *
→ heeyeon to fz f-3 → → I
result
→aq -
Facility name price units
Facility name price units
Facility name price units
-7 null null null
""on
Java Tutorials - Week 9
Mobile App Development in Android Studio Model, View, Controller
GUI Components - Text -> TextView - Text -> Plain Text - Containers -> Spinner - Buttons -> Button
App: Greeting App: Counter
**fate at.tn#reiiEi%aenter Wont
Mr .
Tweensaffueeeirgs outputfountevalz#
View vs. Controller: Event-Driven Programming
ControllerView
- Define Control Methods - Retrieve Inputs from GUI - Display Outputs on GUI
- Layouts GUI Components - Declare id’s of GUI Components - Attach/Register Control Methods
Each user interaction with a GUI component generates an event whose occurrence executes the attached/registered control method
GOI activity-mainland qtk-mdceeief.JO o , button dick Ef
'
→ for
"i →
Controller
View
- Define Control Methods - Retrieve Inputs from GUI - Call Methods on model Objects - Display Outputs on GUI
- Layout GUI Components - Declare id’s of GUI Components - Attach Control Methods
Model-View-Controller: Separation of Concerns
retrieve inputs from GOI
Java Tutorials - Week 10
Calculating Distances between Cities
µ 1st dimension o l Z
Hop .
"
2yd dimension list CITED ( intersection of 2ndrows
° i z s know Kaduna 3rd column )
HELIO → I 2 3 4 Cinder cadet - o l 2 3 Tato Tato
I → to b , I § 1st 2nd
2 → 9 10 11 12 diner .) Atmel . ) .
Creating a new 2D Array Object
° =
ww3→ 9110111112
0
1
2
3
4
5
6
BOSTON
NEW_YORK
ATLANTA
MIAMI
DALLAS
HOUSTON
0
983
787
714
1375
967
1087
983
0
214
1102
1763
1723
1842
787
214
0
888
1549
1548
1627
714
1102
888
0
661
781
810
1375
1763
1549
661
0
1426
1187
967
1723
1548
781
1426
0
239
1087
1842
1627
810
1187
239
0
distance CITED
Java Tutorials - Week 11
Two-Dimensional Arrays Part I: Utility Methods
Problem: Given an input 2D array of integers, return a string displaying its values: row by row vs. col by col (assuming a rectangle).
a
a
4*3 3*4 r C r C O I
o o O O N - 1 2 34
I I - O o
° I 3 '
I 2
I 3 - f
2
Problem: Given an input 2D array of integers, return its overall average vs. row averages.
a
a
6.5
6.0 ~ 6
Problem: Given an input 2D array of integers, return an array of size 2 storing its maximum and minimum values.
a
a
Tnittdmax Een Exercise ,8"
'I'EY - n , ios. a
? ?
{ 10312,11} ~ 'T
Problem: Given an input 2D array of integers, return the row with the maximum sum.
a
→ Exercise
.
\ . vwwsun maxthowsum wwtndex ~ 10 10 10 10 41 40 O
' TEN -v 4¥44 I
-42913 loop 38 '
return a[nowIndex]
Problem: Given an input 2D array of integers, determine if elements are all positive.
a
a
as soon ~ ~ I 10 5 7
Determine if existential,'men"¥%o1a¥onaw.tn ~ 6 2 12 9 there is at least one now
found , ~ 3 8 4 11
whose elements are - F T - exit & conclude ~
u
4 i fake → i = ~ 41numerals .
2nd dimension. ' i .
- ' '
Problem: Given an input 2D array of integers, determine if it is a rectangle (i.e., each row has the same number of columns).
a
a
= ~
Problem: Given an input 2D array of integers, determine if it is a square (i.e., each row has the same number of columns, and that number is equal to the number of rows of the 2-D array).
a
a
RECTANGLE
} →4
F a
Problem: Given an input 2D array of integers, return a string array of size 2 displaying the lower-left and upper-left triangular areas of elements. Assumption: The input 2D array is of a square shape.
a
a
.
Upper -Left o ~)
ATIITOJAEIITII ELITE] upper bound of 'C 'd ~ .
.
EECS1022 Programming for Mobile Computing (Winter 2021)
Java Tutorials - Week 12
Java API - Developing a Birthday Book using ArrayList vs. Hashtable
domain range
Inyo"n bd I
:O: bbI BB
BirthdayBookV2 - Tracing Hashtable Methods

Recommended