ECP4136 Java Technology

skatechildrenSoftware and s/w Development

Nov 3, 2013 (3 years and 10 months ago)

74 views

ECP4136 Java Technology

Tutorial 7

Previous Tutorial


Two classes


Anibot

and
AnibotRace

AnibotRace

-

firstPlayer : Anibot

-

secondPlayer : Anibot

-

lastResult : String

-

distance : int

-

raceCount : int

+ AnibotRace (p1 : Anibot, p2 :


Anibot, distance : int)

+ setFirstPlayer (p : Anibot) : void

+ setSecondPlayer (p : Anibot) : void

+ setDistance (d : int) : void

+ getDistance() : int

+ getCount() : int

+ race() : void

+ toString() : String

Anibot

-

name : String

-

speed : int

-

numAnibot : int

+ Anibot ()

+ Anibot (name : String)

+ Anibot (name : String, speed : int)

+ setName (name : String) : void

+ setSpeed (speed: int) : void

+ getName() : String

+ getSpeed() : int

+ toString() : String

Previous Tutorial

Self
-
assessment >
Anibot

class

a)
Use “this” to call overloaded constructor


setSpeed

method and constructors







Advantages?




Two
-
parameter
constructor

One
-
parameter
constructor

Zero
-
parameter
constructor

this(“Anibot”, 1)

this(name, 1)

Previous Tutorial

Self
-
assessment >
Anibot

class

b)
Ensure that speed is a positive integer
value?


setSpeed

method and constructors


May use ternary operator, e.g:



this.speed = (speed>0) ? speed : 1




Previous Tutorial

Self
-
assessment >
Anibot

class

c)
Reuse of code


setName

&
setSpeed

d)
Double check on the variable names (e.g.
numAnibot
) and method names (e.g.
count()

)in the source code.




Previous Tutorial

Self
-
assessment >
AnibotRace

class

a)
Understanding of question


about the race

b)
Initialise the number of race in constructor?

c)
Calculated time


int or double?


e.g. 25.00000

d)
Check if the distance provided is a positive
integer value?



Tutorial 7


Apply the
Anibot

and
AnibotRace

completed in Tutorial 6


Refresh


GUI application


Class design


New stuffs


java.util.ArrayList


javax.swing.JTextArea


Activities


Revise Tutorial 6


(10
-
15 mins)


Work on Tutorial 7


(1 h)


Discussion on Tutorial 7


(30mins)