Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het...

19
Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh 2010-06-18 1 Het assessment 5 Figuur 1: GUI Het assessment levert voor de student een cijfer op dat 60% uitmaakt van het het eindcijfer. De resterend 40% wordt bepaald op basis van een beoordeling van het tentamen en het ingeleverde werk van de prakticum opdrachten. 1.1 De omgeving Voor elke deelnemer staat een pc gereed, waarop linux draait met netbeans voor het programmeerwerk en firefox als browser voor het doorzoeken van de java API. Je werkt dus individueel. 10 1.2 De werkwijze Je gebruikt een subversion server voor je repository. Daartoe heb je ook op papier de gegevens gekregen die nodig zijn om een verbinding op te bouwen. De uri van je persoonlijke repository en de naam van de server staan ook op dat blad. Elke student heeft een persoonlijke svn repository op de examen server. Deze repository bevat het startproject. Om 15 het te kunnen gebruiken kun je het met de hand (via de command line) uitchecken, of via netbeanssubversion checkout 1

Transcript of Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het...

Page 1: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

Informatie voor het proef assessment SEN1op 18 juni 2010

Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2010-06-18

1 Het assessment5

Figuur 1: GUI

Het assessment levert voor de student een cijfer op dat 60% uitmaakt van het het eindcijfer. De resterend 40% wordtbepaald op basis van een beoordeling van het tentamen en het ingeleverde werk van de prakticum opdrachten.

1.1 De omgeving

Voor elke deelnemer staat een pc gereed, waarop linux draait met netbeans voor het programmeerwerk en firefox alsbrowser voor het doorzoeken van de java API. Je werkt dus individueel.10

1.2 De werkwijze• Je gebruikt een subversion server voor je repository. Daartoe heb je ook op papier de gegevens gekregen die nodig

zijn om een verbinding op te bouwen. De uri van je persoonlijke repository en de naam van de server staan ookop dat blad.

• Elke student heeft een persoonlijke svn repository op de examen server. Deze repository bevat het startproject. Om15

het te kunnen gebruiken kun je het met de hand (via de command line) uitchecken, of via netbeans→ subversion→checkout

1

Page 2: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

1.3 Het spel 1 HET ASSESSMENT

• Vervolgens kun je met NetBeans aan de slag.

• Iedereen dient geregeld in subversion in te checken: typisch als je een nieuwe functionaliteit hebt toegevoegddoor implementatie van een methode en de bijbehorende testmehode(n). Je bent verplicht duidelijk commentaarte leveren bij elke commit opdracht. Aan de hand van deze commits kunnen we je ontwikkelstrategie volgen.

1.3 Het spel5

Het spelverloop in een speelronde is in het sequentiediagram gegeven. Zie figuur 2.Elk van de drie wielen toont in de ruststand drie plaatjes. Met de wielen naast elkaar, kan je die plaatjes op drie hori-zontale lijnen of de twee diagonalen beschouwen. Deze 5 verbindende lijnen zijn in de GUI zichtbaar en selecteerbaar.Deze vijf lijnen worden aangeduid met R1, R2 en R3 voor de horizontale lijnen en met D1 en D2 voor de diagonalelijnen. (Zie figuur 1.) De enum PlayLine beheert deze vijf strings. De GUI is bedrijfklaar. Je kunt er kennis mee10

maken door de Main.java klasse als applicatie op te starten.Om te winnen, moet zich op een speellijn een bepaalde combinatie van plaatjes bevinden. Een speciale rol neemt dehoofdprijs of “prize” in het Engels in. In dit spel is dat Tux, die Linux mascotte.De speler kan op meedere lijnen tegelijk spelen, maximaal op drie! De mogelijke speellijnen zijn de al genoemdehorizontalen en diagonalen. De speler kiest een lijn waarop hij wil wedden door ze aan te vinken met een checkbox.15

Om iets te kunnen winnen moet de speler een bedrag inzetten en minstens een speellijn gekozen hebben. De inzet geldtper speellijn.Aansluitend wordt het spel met behulp van de start- of swing-knop gestart. De GUI geeft inzet als integer en speellijnenals array van strings door via de setBet-methode aan de klasse IconSlotMachine. Als deze gegevens wordengeaccepteerd, wordt de inzet per speellijn direct van het saldo afgetrokken. De wielen beginnen te draaien en stoppen na20

enige tijd op een door het toeval bepaalde plaats. Dan wordt bepaald hoeveel er gewonnen werd. Dit bedrag wordt bijhet saldo geteld.

One line has PointsThree tux icons 10Two tux icons 7One tux icon plus a non-tux double 7One tux icon 5Three times a non-tux icon 3A double non-tux icon 1All icons different and tux in the center 25

Tabel 1: Rules

De combinaties die tot winst leiden kun je aflezen uit tabel 1. Een spel mag alleen gestart worden als het saldo hooggenoeg is om inzet maal het aantal speellijnen te betalen. De totale inzet mag dus nooit hoger zijn als het saldo. Alsaan deze voorwaarde niet is voldaan, dan moet setBet een BetException opwerpen. Men kan het saldo verhogen door25

geld in te werpen. Dat wordt gesimuleerd door de “Insert Coin” knop. Deze heeft geen invloed op het spelverloop enkomt daarom niet voor in het sequentiediagram.Het spel wordt gestart met een saldo van 100 munten. Normaal gesproken zou de speler zich moeten kunnen latenuitbetalen. Deze mogelijkheid is spijtig genoeg niet aanwezig.

1.4 Het ontwerp30

In figuur 3 staat een klassendiagram gegeven; de klassen IconSlotMachine, Game, PlayField en LineScorebehoren tot de package iconslotmachine. Figuur 2 geeft een sequentiediagram van de normale afloop van eengokronde weer.

• De klasse IconSlotMachine vormt de toegang naar de intelligentie (dat wat je moet bouwen!) van de slotma-chine gezien vanuit de gui. De methode setBet biedt de mogelijkheid om de waarde van het bod en de lijnen35

waarop je gokt door te geven. Deze methode wordt aangeroepen als je op de startknop van de gokkast klikt. Demethode submitRows wordt aangeroepen zodra de wielen van de gokkast stil staan. Deze methode bepaalt hetresultaat en past het saldo aan met de eventuele winst.Verder heeft deze klasse de methoden getBalance ensetBalance bij het attribuut balance, het saldo.

2

Page 3: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

1 HET ASSESSMENT 1.4 Het ontwerp

getP

layL

ineV

alue

(line

)

loop

: eac

h be

tline

:Icon

Slo

tMac

hine

getC

redi

ts(b

etlin

e)

cred

its

cred

its

line:

Line

Sco

re

:Gam

e

setP

layF

ield

(pf)

isJa

ckP

ot()

addT

oBal

ance

(cre

dits

)

getB

alan

ce()

isJa

ckpo

t()

disp

lay

bala

nce

pf:P

layF

ield

swin

g th

em

achi

ne:Slo

tMac

hine

Fra

me

subm

itRow

s(ro

w1,

row

2,ro

w3)

new

sp

in w

heel

s

whe

els

stop

ped

setB

et(b

et,s

elec

tedL

ineC

odes

)

Figuur 2: Sequence Diagram

3

Page 4: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

1.4 Het ontwerp 1 HET ASSESSMENT

Ga

me

-pri

zeIc

on

:Str

ing

-Ja

ckp

ot:

bo

ole

an

ge

tCre

dit

s(P

layL

ine

[]):

int

-ge

tCre

dit

s(L

ine

Sco

re):

int

-co

mp

ute

Jack

po

t()

+is

Jack

po

t():

bo

ole

an

11

Ma

in

Ico

nS

lotM

ach

ine

-ba

lan

ce:i

nt

-be

t:in

t-n

rOfL

ine

s:in

t-l

ine

s:S

trin

g[]

11

Slo

tMa

chin

eF

ram

e

1

1

ico

nsl

otm

ach

ine

Lin

eS

core

-Str

ing

[] s

core

+L

ine

Sco

re(S

trin

g[]

)co

nta

ins(

Str

ing

, in

t):b

oo

lea

nco

nta

insN

ot(

Str

ing

):b

oo

lea

nco

nta

insD

ou

ble

():b

oo

lea

nco

nta

insT

rip

le()

:bo

ole

an

slo

tma

chin

e

Be

tExc

ep

tio

n

Slo

tMa

chin

eR

an

kin

gA

da

pte

r +

sub

mit

Ro

ws(

Str

ing

[],

Str

ing

[],

Str

ing

[])

+se

tBa

lan

ce(i

nt

ba

lan

ce)

+g

etB

ala

nc

e()

:in

t+

setB

et(

int

be

t, P

layL

ine

[] s

ele

cte

dL

ine

Co

de

s)

th

row

s B

etE

xce

pti

on

+a

dd

To

Ba

lan

ce(i

nt:

am

ou

nt)

+g

etC

ost

(in

t,P

layL

ine

s[])

:in

t+

isJa

ckP

ot(

):b

oo

lea

n+

ge

tPla

yLin

eV

alu

e(P

layL

ine

):in

t

«in

terf

ace

»S

lotM

ach

ine

+su

bm

itR

ow

s(S

trin

g[]

, S

trin

g[]

, S

trin

g[]

)+

setB

ala

nce

(in

t b

ala

nce

)+

ge

tBa

lan

ce

():i

nt

+se

tBe

t(in

t b

et,

Pla

yLin

e[]

se

lect

ed

Lin

eC

od

es)

thro

ws

Be

tExc

ep

tio

n+

ad

dT

oB

ala

nce

(in

t:a

mo

un

t)+

ge

tCo

st(i

nt,

Pla

yLin

es[

]):i

nt

+is

Jack

Po

t():

bo

ole

an

+g

etP

layL

ine

Va

lue

(Pla

yLin

e):

int

slo

tma

chin

eg

ui

Pla

yFie

ld-r

ow

1:S

trin

g[]

-ro

w2

:Str

ing

[]-r

ow

3:S

trin

g[]

ge

tRo

w(P

layL

ine

):S

trin

g[]

isN

ine

Dif

fere

nt(

):b

oo

lea

nm

idd

leIc

on

IsT

ux(

):b

oo

lea

n

Figuur 3: Class Diagram

4

Page 5: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

1 HET ASSESSMENT 1.4 Het ontwerp

Class: IconSlotMachine

Responsibilities:communication with the gui, to make it possible for the gui to:● give the bet and the playlines the player has chosen,● give the rows that after a swing are visible on the machine,● get the information for this game so the gui can, among other

things, show the new balance.

IconSlotMachine implements the SlotMachine interface:void setBalance(int balance);void addToBalance(int amount);int getBalance();boolean isJackPot();int getCost(int pointValue, PlayLine[] lines);void setBet(int pointValue, PlayLine[] selectedLineCodes) throws BetException;boolean isWinLine(PlayLine line);void submitRows(String[] row1, String[] row2, String[] row3);String getMessage();

Collaborations:GamePlayFieldPlayLine

• De klasse LineScore is gemaakt om de score van een speellijn te analyseren ten behoeve van de klasse Game.De data van deze klasse bestaat uit een array van Strings, 3 in dit geval. De parameter van de constructor is een ar-ray van strings, bijvoorbeeld {”sun”,”java”,”tux”} Zie bovenstaand voorbeeld. Deze klasse bevat hulpmethodenom de score te kunnen analyseren en daarmee het aantal credits te bepalen.5

Class: LineScore

Responsibilities:Class to do the calculations on one possible row of strings, a so called playLine. These calculations should make it easy for the Game class to calculate the credits for a game.

The following methods are present:

The constructor:public LineScore(String[] playLine)Check if the row contains a string zero or more times:public boolean contains(String s, int times)Check if the row contains a string zero or more times:public boolean containsNot(String s)Check if the row contains three identical strings:public boolean containsTriple()Check if the row contains exactly two equal strings:public boolean containsDouble()

Collaborations:

• De klasse Game berekent bij een bepaalde score het aantal credits, punten. Daartoe dient de methodegetCredits(PlayLine[]). PlayLine is een enum. Het attribuut prizeIcon bevat de string die heticon vertegenwoordigt dat meer punten oplevert als het in de score voorkomt. Standaard is de waarde vanprizeIcon gelijk aan ”tux”, de naam van de Linux-pinguin.10

5

Page 6: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

1.4 Het ontwerp 1 HET ASSESSMENT

Class: Game

Responsibilities:Implement the rules of the game such as: how many points does one get for a line of three identical icons. For each line the score is calculated, but this task is delegated to the class LineScore. The PlayField is set by the IconSlotMachine and represents the icons that are visible on the slotmachine after a swing. Game calculates the following:

● the score for each possible playline,● if the jackpot is reached, ● which of the lines have the maximum score,● the new balance.

The following methods are present:void setPlayField(PlayField playField)int getCredits(PlayLine[] betLines)int getCredits(LineScore score)private boolean computeJackpot()private PlayLine getMaxPlayLine()public boolean isJackPot()

Collaborations:LineScorePlayFieldPlayLine

• De klasse PlayField is gemaakt om de totale score van een spel door te geven van de slotmachine naar deklasse Game. De data van deze klasse bestaat uit een drie arrays van Strings, 3 in dit geval. Zie voorbeeld bij deklasse LineScore. Deze klasse bevat eventueel hulpmethoden om de score te kunnen analyseren.

Class: PlayField

Responsibilities:To hold the outcome of one game: for every row of icons on the slotmachine's wheels there is an array of strings in the PlayField class. Useful operations can be done in PlayField, but not those that are typical for a certain slotmachine game. The PlayField class can be useful for several other slotmachines.

A constructor:PlayField(String[] row1, String[] row2, String[] row3)A method to obtain a certain line of the playfield, in this case a choice out of 3 horizontal lines and 2 diagonal lines:String[] getRow(PlayLine pl)A method to check if all icons in the playfield are different:private boolean allNineDifferent()A method for the client class of PlayField, in this case Game:boolean isNineDifferent()

Collaborations:PlayLine

5

1.4.1 Hint bij het testen

In de klasse PlayFieldTest.java bevinden zich enkele hulpmethoden die handige PlayFields genereren voorverschillende tests. Omdat je de rows ook uit de playfield kunt halen (getten), zijn deze playfields ook handig byLineScore en Game tests.In het commentaar en de testmethode-namen vind je nog wat terug van een testplan. Hij lijkt ons handig dit te volgen.10

6

Page 7: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 1.5 Beoordelingsnormen

1.5 Beoordelingsnormen

Voor elk van de methoden die je moet implementeren en te testen is de puntenverdeling in tabel 2 vastgesteld.

Tabel 2: Puntenverdeling

klasse methode puntenLineScore

contains(String,int) 10containsNot(String) 10containsDouble() 10containsTriple() 10

PlayFieldisNineDifferent 10

GamegetCreditsForLine 10getCeditsWon 10

IconSlotMachinesetBet 10subMitScores 10

Let op: Alleen voor methoden die ook getest zijn worden punten vergeven. Het hoofdthema van deze module isimmers testen. Dat zijn samen 90 punten; cijfer wordt dan aantal behaalde punten plus 10 en dat geheel gedeeld door10, net zoals je gewend bent.5

2 Code listings

De broncode files die je dient aan te vullen vind je in onderstaande listings. De tests steeds als eerste.

2.1 LineScore.java and Test

Listing 1: LineScoreTest.java1package n l . f o n t y s . i c o n s l o t m a c h i n e ;23import j u n i t . f ramework . T e s t C a s e ;45p u b l i c c l a s s L i n e S c o r e T e s t ex tends T e s t C a s e {6p r i v a t e L i n e S c o r e s c o r e ;78@Override9p r o t e c t e d void se tUp ( ) throws E x c e p t i o n {10super . se tUp ( ) ;11s c o r e =new L i n e S c o r e ( new S t r i n g [ ]{ ” aap ” , ” mies ” , ” noo t ” } ) ;12}1314@Override15p r o t e c t e d void tearDown ( ) throws E x c e p t i o n {16super . tearDown ( ) ;17s c o r e = n u l l ;18}1920/∗21∗ T e s t method f o r c t o r22∗ /23p u b l i c f i n a l vo id t e s t C o n s t r u c t ( ) {24a s s e r t F a l s e ( s c o r e . c o n t a i n s T r i p l e ( ) ) ;25}2627/∗∗28∗ T e s t method f o r s l o t m a c h i n e . Score . s e t S c o r e ( S t r i n g [ ] )29∗ t e s t c o n a t i n s f o r i n s t a n c e30∗ /31p u b l i c f i n a l vo id t e s t N e w S c o r e ( ) {32/ / TODO33f a i l ( ” t e s t n o t implemented ” ) ;34}

7

Page 8: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2.1 LineScore.java and Test 2 CODE LISTINGS

353637/∗∗38∗ T e s t method f o r s l o t m a c h i n e . Score . c o n t a i n s ( S t r i n g , i n t )39∗ T e s t w i t h c o n t a i n i n g and w i t h o u t f o r v a r i o u s numbers o f i c o n s40∗ /41p u b l i c f i n a l vo id t e s t C o n t a i n s ( ) {42/ / TODO43f a i l ( ” t e s t n o t implemented ” ) ;44}4546/∗∗47∗ T e s t method f o r s l o t m a c h i n e . Score . c o n t a i n s N o t ( S t r i n g )48∗ T e s t f o r f a l s e and t r u e .49∗ /50p u b l i c f i n a l vo id t e s t C o n t a i n s N o t ( ) {51/ / TODO52f a i l ( ” t e s t n o t implemented ” ) ;53}5455/∗∗56∗ T e s t method f o r s l o t m a c h i n e . Score . c o n t a i n s T r i p l e ( )57∗ T e s t w i t h and w i t h o u t t r i p p l e s58∗ /59p u b l i c f i n a l vo id t e s t C o n t a i n s T r i p l e ( ) {60/ / TODO61f a i l ( ” t e s t n o t implemented ” ) ;62}6364/∗∗65∗ T e s t method f o r s l o t m a c h i n e . Score . c o n t a i n s D o u b l e ( )66∗ T e s t w i t h and w i t h o u t d o u b l e s b u t a l s o w i t h t r i p l e s67∗68∗ /69p u b l i c f i n a l vo id t e s t C o n t a i n s D o u b l e ( ) {70/ / TODO71f a i l ( ” t e s t n o t implemented ” ) ;72}73} /∗ e o f L i n e S c o r e T e s t . j a v a ∗ /

8

Page 9: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 2.2 PlayField.java and Test

Listing 2: LineScore.java1package n l . f o n t y s . i c o n s l o t m a c h i n e ;23import j a v a . u t i l . A r r ay s ;4/∗∗5∗ Compute t h e v a l u e o f a p l a y l i n e6∗ @author ode7∗ @author home8∗9∗ /10p u b l i c c l a s s L i n e S c o r e {11/∗∗ The s t r i n g s on t h e p l a y l i n e , s o r t e d . ∗ /12p r i v a t e f i n a l S t r i n g [ ] p l a y L i n e ;1314/∗∗15∗ C o n s t r u c t o r .16∗ The s t r i n g s are s t o r e d i n s o r t e d o r d e r .17∗ @param newscore a r r a y o f s t r i n g s r e p r e s e n t i n g t h e i c o n s18∗ /19p u b l i c L i n e S c o r e ( S t r i n g [ ] l i n e ) {20/ / make s u r e n o t t o a l t e r t h e l i n e21S t r i n g [ ] i n l i n e = new S t r i n g [ l i n e . l e n g t h ] ;22System . a r r a y c o p y ( l i n e , 0 , i n l i n e , 0 , l i n e . l e n g t h ) ;23/ / s o r t my copy t o make t h i n g s e a s i e r .24A r r ay s . s o r t ( i n l i n e ) ;25t h i s . p l a y L i n e = i n l i n e ;26}2728/∗∗29∗ @param s s t r i n g t o s e a r c h f o r30∗ @param t i m e s number o f t i m e s t h e s t r i n g s h o u l d appear i n t h e s c o r e31∗ @return t r u e i f g i v e n s t r i n g appears t i m e s n s c o r e32∗ /33p u b l i c boolean c o n t a i n s ( S t r i n g s , i n t t i m e s ){34/ / TODO35re turn f a l s e ;36}3738/∗∗39∗ @param s s e a r c h s t r i n g40∗ @return t r u e i f s t r i n g s does n o t appear i n s c o r e41∗ /42p u b l i c boolean c o n t a i n s N o t ( S t r i n g s ) {43/ / TODO44re turn f a l s e ;45}46/∗∗47∗ @return t r u e i f s c o r e a r r a y c o n t a i n s same v a l u e on e v e r y i n d e x48∗ /49p u b l i c boolean c o n t a i n s T r i p l e ( ){50/ / TODO51re turn f a l s e ;52}53/∗∗54∗ @return r e t u r n s t r u e i s e x a c t l y two s t r i n g s i n s c o r e a r r a y are e q u a l55∗ /56p u b l i c boolean c o n t a i n s D o u b l e ( ){57/ / TODO58re turn f a l s e ;59}60} /∗ e o f L i n e S c o r e . j a v a ∗ /

2.2 PlayField.java and Test

Listing 3: PlayFieldTest.java1/∗∗2∗3∗ /4package n l . f o n t y s . i c o n s l o t m a c h i n e ;56import j u n i t . f ramework . T e s t C a s e ;7import n l . f o n t y s . s l o t m a c h i n e g u i . P l a y L i n e ;89/∗∗10∗ @author hom11∗12∗ /13p u b l i c c l a s s P l a y F i e l d T e s t ex tends T e s t C a s e {1415p r i v a t e P l a y F i e l d p f ;16/∗ ( non−Javadoc )17∗ @see j u n i t . f ramework . Te s t C a s e # se tUp ( )18∗ /1920p r o t e c t e d void se tUp ( ) throws E x c e p t i o n {

9

Page 10: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2.2 PlayField.java and Test 2 CODE LISTINGS

21super . se tUp ( ) ;22p f = g e t N i n e D i f f e r e n t ( ) ;23}2425/∗ ( non−Javadoc )26∗ @see j u n i t . f ramework . Te s t C a s e # tearDown ( )27∗ /28p r o t e c t e d void tearDown ( ) throws E x c e p t i o n {29super . tearDown ( ) ;30p f = n u l l ;31}3233/∗∗34∗ T e s t method f o r {@link n l . f o n t y s . s l o t m a c h i n e . i c o n s l o t m a c h i n e . P l a y F i e l d # P l a y F i e l d ( ) } .35∗ /36p u b l i c vo id t e s t P l a y F i e l d ( ) {37/ / TODO38f a i l ( ” t e s t n o t implemented ” ) ;39}4041/∗∗42∗ T e s t method f o r P l a y F i e l d . getRow ( P l a y L i n e )43∗ /44p u b l i c vo id t e s tGe tRow ( ) {45/ / TODO46f a i l ( ” t e s t n o t implemented ” ) ;47}4849/∗∗50∗ T e s t method f o r {@link n l . f o n t y s . s l o t m a c h i n e . i c o n s l o t m a c h i n e . P l a y F i e l d # i s J a c k p o t ( ) } .51∗ /52p u b l i c vo id t e s t I s N i n e D i f f e r e n t ( ) {53/ / TODO54f a i l ( ” t e s t n o t implemented ” ) ;55}5657/∗∗ j u s t s a t i s f y c o v e r a g e ∗ /58p u b l i c vo id t e s t T o S t r i n g ( ) {59pf = g e t N i n e D i f f e r e n t ( ) ;60p f . t o S t r i n g ( ) ;61}6263/∗∗64∗ Helper methods . Produces v a r i o u s p l a y f i e l d s t h a t may come handy i n a t e s t .65∗ T h i s P l a y F i e l d i s JackPo t i n Game(” z u s ”) and n o t JackPo t i n any o t h e r Game .66∗ @return a N i n e F i e l d D i f f e r e n t P l a y f i e l d .67∗ /68s t a t i c P l a y F i e l d g e t N i n e D i f f e r e n t ( ) {69re turn new P l a y F i e l d (70new S t r i n g [ ]{ ” aap ” , ” mies ” , ” noo t ”} ,71new S t r i n g [ ]{ ”wim” , ” zus ” , ” j e t ”} ,72new S t r i n g [ ]{ ” t e u n ” , ” vuur ” , ” g i j s ” } ) ;73}7475/∗∗76∗ Helper methods . Produces v a r i o u s p l a y f i e l d s t h a t may come handy i n a t e s t .77∗78∗ @return a N i n e F i e l d D i f f e r e n t P l a y f i e l d .79∗ /80s t a t i c P l a y F i e l d g e t U p p e r R i g h t ( ) {81re turn new P l a y F i e l d (82new S t r i n g [ ]{ ” aap ” , ” aap ” , ” aap ”} ,83new S t r i n g [ ]{ ”wim” , ” aap ” , ” aap ”} ,84new S t r i n g [ ]{ ” t e u n ” , ” vuur ” , ” aap ” } ) ;85}8687/∗∗88∗ Helper methods . Produces v a r i o u s p l a y f i e l d s t h a t may come handy i n a t e s t .89∗90∗ @return a N i n e F i e l d D i f f e r e n t P l a y f i e l d .91∗ /92s t a t i c P l a y F i e l d ge tUpperRigh tMin ( ) {93re turn new P l a y F i e l d (94new S t r i n g [ ]{ ” aap ” , ” aap ” , ” aap ”} ,95new S t r i n g [ ]{ ”wim” , ” aap ” , ” aap ”} ,96new S t r i n g [ ]{ ” t e u n ” , ” aap ” , ” vuur ” } ) ;97}98} /∗ e o f P l a y F i e l d T e s t . j a v a ∗ /

10

Page 11: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 2.2 PlayField.java and Test

Listing 4: PlayField.java1/∗∗2∗3∗ /4package n l . f o n t y s . i c o n s l o t m a c h i n e ;56import j a v a . u t i l . S e t ;7import j a v a . u t i l . T r e e S e t ;89import n l . f o n t y s . s l o t m a c h i n e g u i . P l a y L i n e ;1011/∗∗12∗ The s e t o f n i n e inconnames v i s i b l e a t t h e end o f a game .13∗ O p e r a t i o n s l i k e r a n k i n g and j a c k p o t are s u p p o r t e d .14∗ @author ode15∗16∗ /17p u b l i c c l a s s P l a y F i e l d {18/∗∗ The rows , top , middle , bot tom , s t o r e d i n r e c e i v e d o r d e r19∗ ( t h a t i s NOT s o r t e d ) . ∗ /20p r i v a t e f i n a l S t r i n g [ ] row1 , row2 , row3 ;21/∗∗ The d i a g o n a l s , t o p l e f t−>bo t tom r i g h t and22∗ bo t tom l e f t −> t o p r i g h t23∗ /24p r i v a t e f i n a l S t r i n g [ ] d iag1 , d i a g 2 ;25/∗∗ t h e j a c k p u t va lue , i n i t i a l i z e d a t c o n s t r u c t i o n t i m e ∗ /26p r i v a t e f i n a l boolean n i n e D i f f e r e n t ;27/∗∗28∗ C o n s t r u c t p l a y f i e l d w i t h t h r e e rows o f d i g i t s r e p r e s e n t a t i o n s .29∗ Compute SumScores , t h e i r r a n k i n g and j a c k p u t v a l u e .30∗ @param row1 f i r s t row31∗ @param row2 second rows32∗ @param row3 t h i r d row33∗ /34P l a y F i e l d ( S t r i n g [ ] row1 , S t r i n g [ ] row2 , S t r i n g [ ] row3 ) {35t h i s . row1 = row1 ;36t h i s . row2 = row2 ;37t h i s . row3 = row3 ;38t h i s . d i a g 1 = new S t r i n g [ ]{ row1 [ 0 ] , row2 [ 1 ] , row3 [ 2 ]} ;39t h i s . d i a g 2 = new S t r i n g [ ]{ row3 [ 0 ] , row2 [ 1 ] , row1 [ 2 ]} ;40t h i s . n i n e D i f f e r e n t = a l l N i n e D i f f e r e n t ( ) ;41}4243/∗∗ D e f a u l t Ctor , empty f i e l d s ∗ /44P l a y F i e l d ( ) {45t h i s ( new S t r i n g [ ] { ” ” , ” ” , ” ” } ,46new S t r i n g [ ] { ” ” , ” ” , ” ” } ,47new S t r i n g [ ] { ” ” , ” ” , ” ” } ) ;48}4950/∗∗51∗ Gets t h e s t r i n g s on a l i n e o f t h e P l a y F i e l d .52∗ T h i s code i s g i v e n d u r i n g t h e exam .53∗54∗ @param p l one o f P l a y L i n e ( D1 , D2 , R1 , R2 , R3 )55∗ @return Array o f s t r i n g s on t h a t P l a y l i n e , from l e f t t o r i g h t .56∗ /57S t r i n g [ ] getRow ( P l a y L i n e p l ){58S t r i n g [ ] r e s u l t = n u l l ;59sw i t ch ( p l ) {60case R1 : r e s u l t = row1 ; break ;61case R2 : r e s u l t = row2 ; break ;62case R3 : r e s u l t = row3 ; break ;63case D1 : r e s u l t = d i a g 1 ; break ;64case D2 : r e s u l t = d i a g 2 ; break ;65}66re turn r e s u l t ;67}6869/∗∗70∗ Compute t h e v a l u e o f a l l D i f f e r e n t .71∗72∗ Hin t : use some k i n d o f s e t .73∗ t o c o u n t t h e number o f d i f f e r e n t i c o n s . I f t h i s amount i s74∗ t h e same as t h e number o f f i e l d s , t h e t h e outcome i s t r u e , e l s e f a l s e75∗76∗ @return t r u e i s a l l i c o n s are d i f f e r e n t , f a l s e i n a l l o t h e r c a s e s .77∗ /78boolean a l l N i n e D i f f e r e n t ( ){79Set<S t r i n g> s e t = new TreeSe t<S t r i n g > ( ) ;80/ / TODO81re turn f a l s e ;82}8384/∗∗85∗ Gets t h e j a c p o t boo lean .86∗ @return t h e j a c k p o t .87∗ /88boolean i s N i n e D i f f e r e n t ( ){89re turn t h i s . n i n e D i f f e r e n t ;

11

Page 12: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2.3 Game.java and Test 2 CODE LISTINGS

90}9192p u b l i c S t r i n g t o S t r i n g ( ){93re turn ” [ ”+row1 [ 0 ] + ” , ”+row1 [ 1 ] + ” , ”+row1 [ 2 ] + ” ]\n ”94+” [ ”+row2 [ 0 ] + ” , ”+row2 [ 1 ] + ” , ”+row2 [ 2 ] + ” ]\n ”95+” [ ”+row3 [ 0 ] + ” , ”+row3 [ 1 ] + ” , ”+row3 [ 2 ] + ” ]\n ” ;96}9798} /∗ e o f P l a y F i e l d . j a v a ∗ /

2.3 Game.java and Test

Listing 5: GameTest.java1/∗∗2∗3∗ /4package n l . f o n t y s . i c o n s l o t m a c h i n e ;56import n l . f o n t y s . s l o t m a c h i n e g u i . P l a y L i n e ;7import j u n i t . f ramework . T e s t C a s e ;89/∗∗10∗ Exam t e s t c l a s s .11∗ In t h e comments and t e s t m e t h o d n a m e s you can read some k i n d o f t e s t p lan .12∗ You are a d v i s e d t o use t h i s as a g u i d e l i n e .13∗14∗ @author hom15∗16∗ /17p u b l i c c l a s s GameTest ex tends T e s t C a s e {18p r i v a t e Game game ;1920p r i v a t e s t a t i c f i n a l S t r i n g p r i z e = ” aap ” ;2122/∗ ( non−Javadoc )23∗ @see j u n i t . f ramework . T e s t C a s e # se tUp ( )24∗ /25@Override26p r o t e c t e d void se tUp ( ) throws E x c e p t i o n {27super . se tUp ( ) ;28/ / TODO29}3031/∗ ( non−Javadoc )32∗ @see j u n i t . f ramework . T e s t C a s e # tearDown ( )33∗ /34@Override35p r o t e c t e d void tearDown ( ) throws E x c e p t i o n {36super . tearDown ( ) ;37/ / TODO38}3940/∗∗41∗ T e s t method f o r Game# g e t C r e d i t s ( P l a y L i n e [ ] )} .42∗43∗ T e s t f o r t h r e e t i m e s t h e p r i z e i c o n .44∗ /45p u b l i c vo id t e s t G e t C r e d i t s T r i p p l e P r i z e ( ) {46/ / TODO47f a i l ( ” t e s t n o t implemented ” ) ;48}4950/∗∗51∗ T e s t method f o r Game# g e t C r e d i t s ( P l a y L i n e [ ] )} .52∗53∗ T e s t f o r two t i m e s t h e p r i z e i c o n .54∗ /55p u b l i c vo id t e s t G e t C r e d i t s D o u b l e P r i z e ( ) {56/ / TODO57f a i l ( ” t e s t n o t implemented ” ) ;58}5960/∗∗61∗ T e s t method f o r Game# g e t C r e d i t s ( P l a y L i n e [ ] )} .62∗63∗ T e s t f o r one t i m e t h e p r i z e i c o n .64∗ /65p u b l i c vo id t e s t G e t C r e d i t s S i n g l e P r i z e ( ) {66/ / TODO67f a i l ( ” t e s t n o t implemented ” ) ;68}6970/∗∗71∗ T e s t method f o r Game# g e t C r e d i t s ( P l a y L i n e [ ] )} .72∗

12

Page 13: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 2.3 Game.java and Test

73∗ T e s t f o r no p r i z e i c o n .74∗75∗ /76p u b l i c vo id t e s t G e t C r e d i t s T r i p p l e N o n P r i z e ( ) {77/ / TODO78f a i l ( ” t e s t n o t implemented ” ) ;79}8081/∗∗82∗ T e s t method f o r Game# g e t C r e d i t s ( P l a y L i n e [ ] )} .83∗84∗ T e s t f o r two non p r i z e i c o n s .85∗86∗ /87p u b l i c vo id t e s t G e t C r e d i t s D o u b l e N o n P r i z e ( ) {88/ / TODO89f a i l ( ” t e s t n o t implemented ” ) ;90}9192p u b l i c vo id t e s t G e t C r e d i t s D o u b l e P l u s P r i z e ( ) {93/ / TODO94f a i l ( ” t e s t n o t implemented ” ) ;95}9697p u b l i c vo id t e s t G e t C r e d i t s N o L u c k ( ) {98/ / TODO99f a i l ( ” t e s t n o t implemented ” ) ;100}101102/∗∗103∗ T e s t method f o r {@link n l . f o n t y s . s l o t m a c h i n e . i c o n s l o t m a c h i n e . Game# i s J a c k P o t ( ) } .104∗ /105p u b l i c f i n a l vo id t e s t I s J a c k P o t ( ) {106/ / TODO107f a i l ( ” t e s t n o t implemented ” ) ;108}109110/∗∗111∗ T e s t i s 0 l i n e s r e s u l t s i n 0 c r e d i t s .112∗113∗ /114p u b l i c f i n a l vo id t e s t Z e r o L i n e s B e t ( ){115/ / TODO116f a i l ( ” t e s t n o t implemented ” ) ;117}118} /∗ e o f GameTest . j a v a ∗ /

13

Page 14: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2.3 Game.java and Test 2 CODE LISTINGS

Listing 6: Game.java1package n l . f o n t y s . i c o n s l o t m a c h i n e ;23import n l . f o n t y s . s l o t m a c h i n e g u i . P l a y L i n e ;45/∗∗6∗ The game c l a s s i m p l e m e n t s t h e r u l e s7∗ /8c l a s s Game {9/∗∗10∗ The i c o n which g i v e s e x t r a c r e d i t s when i t i s p r e s e n t i n t h e s c o r e11∗ /12p r i v a t e f i n a l S t r i n g p r i z e I c o n ;13/∗∗ The l a s t p l a y f i e l d i n t h e game ∗ /14p r i v a t e P l a y F i e l d p l a y F i e l d ;15/∗∗ have we h i t t h e j a c k p o t ?∗ /16p r i v a t e boolean j a c k P o t ;17/∗∗ The s c o r e per P l a y L i n e . ∗ /18p r i v a t e i n t [ ] s c o r e P e r P l a y L i n e ;19/∗∗20∗ Ctor21∗ D e f i n e s t h e p r i z e winn ing i c o n .22∗ @param p r i z e23∗ /24Game ( S t r i n g p r i z e ) {25t h i s . p r i z e I c o n = p r i z e ;26t h i s . j a c k P o t = f a l s e ;27s c o r e P e r P l a y L i n e = new i n t [ P l a y L i n e . v a l u e s ( ) . l e n g t h ] ;28}2930/∗∗31∗ R e c e i v e t h e P l a y f i e l d from t h e i c o n s l o t m a c h i n e .32∗ The P l a y F i e l d c o n t a i n s t h e 9 i c o n s t h a t have r e s u l t e d from one ’ swing ’ .33∗34∗ @param p l a y F i e l d35∗ /36void s e t P l a y F i e l d ( P l a y F i e l d p l a y F i e l d ){37t h i s . p l a y F i e l d = p l a y F i e l d ;38/ / compute t h e s c o r e s39t h i s . c a l c u l a t e P l a y L i n e S c o r e s ( ) ;40t h i s . j a c k P o t = c o m p u t e J a c k p o t ( ) ;41}42/∗∗43∗ Compute t h e s c o r e s per l i n e . Computes t h e v a l u e i r r e s p e c t i v e o f44∗ we th er t h e r e was a b e t or n o t .45∗46∗ /47void c a l c u l a t e P l a y L i n e S c o r e s ( ){48f o r ( i n t i =0 ; i< t h i s . s c o r e P e r P l a y L i n e . l e n g t h ; i ++)49t h i s . s c o r e P e r P l a y L i n e [ i ] = 0 ;5051f o r ( P l a y L i n e p l : P l a y L i n e . v a l u e s ( ) ) {52t h i s . s c o r e P e r P l a y L i n e [ p l . o r d i n a l ( ) ]53= g e t C r e d i t s F o r L i n e ( new L i n e S c o r e ( p l a y F i e l d . getRow ( p l ) ) ) ;54}55}56/∗∗57∗ Reed t h e v a l u e o f a l i n e .58∗59∗ @param p l a y L i n e60∗ @return61∗ /62i n t g e t P l a y L i n e V a l u e ( P l a y L i n e p l a y L i n e ){63re turn t h i s . s c o r e P e r P l a y L i n e [ p l a y L i n e . o r d i n a l ( ) ] ;64}65/∗∗66∗ Compute t h e c r e d i t s o f t h e l i n e s t h a t was b e t on , p l u s p o s s i b l e J a c k p o t bonus .67∗ Note t h a t t h e outcome s h o u l d be z e r o i f t h e r e are no b e t l i n e s .68∗69∗ @param b e t L i n e s t h e l i n e s t h a t were b e t on .70∗ @return t h e c r e d i t s earned .71∗ /72i n t ge tCred i t sWon ( P l a y L i n e [ ] b e t L i n e s ){73/ / TODO74re turn 0 ;75}7677/∗∗78∗ r e t u r n s c r e d i t s depend ing on s c o r e c o n t e n t79∗ i f s c o r e c o n t a i n s 3∗ p r i z e I c o n : 10 c r e d i t s80∗ i f s c o r e c o n t a i n s 2∗ p r i z e I c o n : 7 c r e d i t s81∗ i f s c o r e c o n t a i n s 1∗ p r i z e I c o n : 5 c r e d i t s82∗ i f s c o r e c o n t a i n s 3 t i m e s o t h e r i c o n : 3 c r e d i t s83∗ i f s c o r e c o n t a i n s 2 t i m e s o t h e r i c o n : 1 c r e d i t84∗ i n a l l o t h e r c a s e s r e t u r n 0 c r e d i t85∗ @param s c o r e86∗ @return t h e p r o f i t g a in ed by t h i s p l a y87∗ /88i n t g e t C r e d i t s F o r L i n e ( L i n e S c o r e s c o r e ){89/ / TODO

14

Page 15: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 2.4 IconSlotMachine.java and Test

90re turn 0 ;91}9293/∗∗94∗ Compute J a c k p o t from p l a y F i e l d95∗ /96p r i v a t e boolean c o m p u t e J a c k p o t ( ) {97/ / TODO98re turn f a l s e ;99}100/∗∗101∗ Did we h i t t h e J a c k p o t ?102∗ @return j a c k p o t s t a t e103∗ /104p u b l i c boolean i s J a c k P o t ( ) {105re turn t h i s . j a c k P o t ;106}107108/∗∗109∗ @return t h e p r i z e I c o n110∗ /111S t r i n g g e t P r i z e I c o n ( ) {112re turn p r i z e I c o n ;113}114115} /∗ e o f Game . j a v a ∗ /

2.4 IconSlotMachine.java and Test

Listing 7: IconSlotMachineTest.java1/∗∗2∗3∗ /4package n l . f o n t y s . i c o n s l o t m a c h i n e ;56import n l . f o n t y s . s l o t m a c h i n e g u i . B e t E x c e p t i o n ;7import n l . f o n t y s . s l o t m a c h i n e g u i . P l a y L i n e ;8import j u n i t . f ramework . T e s t C a s e ;910/∗∗11∗ @author hom12∗13∗ /14p u b l i c c l a s s I c o n S l o t M a c h i n e T e s t ex tends T e s t C a s e {15p r i v a t e I c o n S l o t M a c h i n e ism ;16/∗∗ t h e s e p l a y f i e l d s are handy i n t h e t e s t s ∗ /17P l a y F i e l d pf9 = P l a y F i e l d T e s t . g e t N i n e D i f f e r e n t ( ) ;1819P l a y F i e l d p f u r = P l a y F i e l d T e s t . g e t U p p e r R i g h t ( ) ;20/∗ ( non−Javadoc )21∗ @see j u n i t . f ramework . T e s t C a s e # se tUp ( )22∗ /23p r o t e c t e d void se tUp ( ) throws E x c e p t i o n {24super . se tUp ( ) ;25ism = new I c o n S l o t M a c h i n e ( 1 0 0 , ” zus ” ) ;26}2728/∗ ( non−Javadoc )29∗ @see j u n i t . f ramework . T e s t C a s e # tearDown ( )30∗ /31p r o t e c t e d void tearDown ( ) throws E x c e p t i o n {32super . tearDown ( ) ;33ism= n u l l ;34}3536/∗∗37∗ T e s t c o n s t r u c t o r38∗ /39p u b l i c vo id t e s t I c o n S l o t M a c h i n e ( ) {40a s s e r t E q u a l s ( 1 0 0 , ism . g e t B a l a n c e ( ) ) ;41}424344/∗∗45∗ T e s t submitRows f o r 9 d i f f e r e n t , n o t j a c k p o t s i t u a t i o n46∗ /47p u b l i c vo id t e s t S ub m i tR o w sN o t J a c k ( ) {48/ / TODO49f a i l ( ” t e s t n o t implemented ” ) ;50}5152/∗∗53∗ T e s t method f o r I c o n S l o t M a c h i n e . s e t B e t54∗55∗ T e s t w i t h a c c e p t a b l e b e t .

15

Page 16: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2.4 IconSlotMachine.java and Test 2 CODE LISTINGS

56∗ /57p u b l i c vo id t e s t S e t B e t O k ( ) {58/ / TODO59f a i l ( ” t e s t n o t implemented ” ) ;60}6162/∗∗63∗ T e s t s e t B e t w i t h t o low a b a l a n c e .64∗65∗ /66p u b l i c vo id t e s t B e t O v e r d r a f t ( ){67/ / TODO68f a i l ( ” t e s t n o t implemented ” ) ;69}7071/∗∗72∗ t e s t f o r a c h e a t a t t e m p t , n e g a t i v e v a l u e i n b e t . ( So l o s s i s a win ) .73∗ /74p u b l i c vo id t e s t B e t N e g a t i v e ( ){75/ / TODO76f a i l ( ” t e s t n o t implemented ” ) ;77}7879/∗∗80∗ T e s t t h e l i n e l i m i t . No more t h e n 3 l i n e s are a l l o w e d b e t .81∗82∗ /83p u b l i c vo id t e s tTooManyLine ( ){84/ / TODO85f a i l ( ” t e s t n o t implemented ” ) ;86}8788/∗∗89∗ T e s t method f o r g e t B a l a n c e . Any one can do t h a t , so you g e t no p o i n t s f o r i t .90∗ Given i n exam .91∗ /92p u b l i c vo id t e s t G e t B a l a n c e ( ) {93a s s e r t E q u a l s ( ” i n i t a l b a l a n c e ” ,100 , ism . g e t B a l a n c e ( ) ) ;94}9596/∗∗97∗ T e s t method f o r s e t B a l a n c e . Any one can do t h a t , so you g e t no p o i n t s f o r i t .98∗ Given i n exam .99∗ /100p u b l i c vo id t e s t S e t B a l a n c e ( ) {101ism . s e t B a l a n c e ( 1 5 0 ) ;102a s s e r t E q u a l s ( ” i n i t a l b a l a n c e 150 ” ,150 , ism . g e t B a l a n c e ( ) ) ;103}104105/∗∗106∗ Add t o b a l a n c e i s n o t t h a t t r i v i a l . T e s t i t .107∗ Given i n exam .108∗ /109p u b l i c vo id t e s t A d d T o B a l a n c e ( ) {110i n t s t a r t B a l a n c e = ism . g e t B a l a n c e ( ) ;111ism . addToBalance ( 5 0 ) ;112a s s e r t E q u a l s ( ” add b a l a n c e 50 ” , s t a r t B a l a n c e +50 , ism . g e t B a l a n c e ( ) ) ;113ism . addToBalance (−25);114a s s e r t E q u a l s ( ” add b a l a n c e −50 ” , s t a r t B a l a n c e +25 , ism . g e t B a l a n c e ( ) ) ;115}116117/∗∗118∗ T e s t method f o r ge tMessage . T e s t i n i t i a l message . Mainly t o keep119∗ c o v e r a g e t e s t ( emma , c o b e r t u r a or h a n s e l ) happy .120∗ /121p u b l i c vo id t e s t G e t M e s s a g e ( ) {122a s s e r t E q u a l s ( I c o n S l o t M a c h i n e . ready , ism . ge tMessage ( ) ) ;123}124125/∗∗126∗ T e s t method f o r g e t C o s t .127∗ T e s t f o r v a r i o u s number o f l i n e s and p o i n t V a l u e s .128∗ /129p u b l i c vo id t e s t G e t C o s t ( ) {130/ / TODO131f a i l ( ” t e s t n o t implemented ” ) ;132}133134/∗∗135∗ T e s t method f o r i s J a c k P o t .136∗ /137p u b l i c vo id t e s t I s J a c k P o t ( ) {138/ / TODO139f a i l ( ” t e s t n o t implemented ” ) ;140}141142/∗∗143∗ T e s t method f o r i s J a c k P o t .144∗ /145p u b l i c vo id t e s t L o o s e ( ) {

16

Page 17: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 2.4 IconSlotMachine.java and Test

146/ / TODO147f a i l ( ” t e s t n o t implemented ” ) ;148}149150/∗∗151∗ T e s t method f o r i s J a c k P o t .152∗ /153p u b l i c vo id t e s t G e t P l a y L i n e V a l u e ( ) {154/ / TODO155f a i l ( ” t e s t n o t implemented ” ) ;156}157158} /∗ e o f I c o n S l o t M a c h i n e T e s t . j a v a ∗ /

17

Page 18: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2.4 IconSlotMachine.java and Test 2 CODE LISTINGS

Listing 8: IconSlotMachine.java1/∗∗2∗3∗ /4package n l . f o n t y s . i c o n s l o t m a c h i n e ;56import n l . f o n t y s . s l o t m a c h i n e g u i . B e t E x c e p t i o n ;7import n l . f o n t y s . s l o t m a c h i n e g u i . S l o t M a c h i n e R a n k i n g A d a p t e r ;8import n l . f o n t y s . s l o t m a c h i n e g u i . P l a y L i n e ;910/∗∗11∗ @author hom12∗ @author ode13∗14∗ /15p u b l i c c l a s s I c o n S l o t M a c h i n e ex tends S l o t M a c h i n e R a n k i n g A d a p t e r {16/∗∗ t h e p l a y e r ’ s c r e d i t ∗ /17p r i v a t e i n t b a l a n c e ;18/∗∗ The game , h av in g t h e r u l e s ∗ /19p r i v a t e Game game ;20/∗∗ The l i n e s t h e b e t was p l a c e d on ∗ /21p r i v a t e P l a y L i n e [ ] l i n e s ;2223/∗∗ messages on win or l o s s ∗ /24f i n a l s t a t i c S t r i n g s u c c e s =”You won ! ” ;25f i n a l s t a t i c S t r i n g l o s t =” Bugger ” ;26f i n a l s t a t i c S t r i n g r e a d y =” Ready ” ;27/∗∗ mutable , t h i s p r i v a t e ∗ /28p r i v a t e S t r i n g r e s u l t M e s s a g e = r e a d y ;29/∗∗30∗ CTor31∗ @param b a l a n c e : i n i t i a l c r e d i t32∗ @param p r i z e : name o f p r i z e i c o n33∗ /34p u b l i c I c o n S l o t M a c h i n e ( i n t b a l a n c e , S t r i n g p r i z e ) {35t h i s . b a l a n c e = b a l a n c e ;36game = new Game ( p r i z e ) ;37}3839/∗∗40∗ R e c e i v e t h e t h r e e a r r a y s o f s t r i n g s from t h e g u i .41∗ From t h i s a P l a y F i e l d i s c o n s t r u c t e d , which i s used t o compute t h e r e s u l t s42∗ and p r o v i d e i n f o r m a t i o n f o r t h e g u i t o c o l l e c t .43∗ For c a l c u l a t i o n r u l e s s e e s t r i n g r u l e s . h tm l44∗45∗ @param row1 t o p row o f iconnames46∗ @param row2 mi dd l e row o f i c o n names47∗ @param row3 bot tom row o f i c o n names48∗ /4950p u b l i c vo id submitRows ( S t r i n g [ ] row1 , S t r i n g [ ] row2 , S t r i n g [ ] row3 ) {51/ / TODO52}53/∗∗54∗ P l a c e s t h e by by t h e u s e r ( p l a y e r ) .55∗56∗ The b e t c o n s i s t s o f a p o i n t v a l u e and t h e s e t o f l i n e s t h a t were57∗ s e l e c t e d ( e n a b l e d ) i n t h i s game .58∗ Throws B e t E x c e p t i o n when i n s u f f i c i e n t c r e d i t .59∗ Throws B e t E x c e p t i o n when t o o many L i n e s . (> 3)60∗ Throws B e t E x c e p t i o n when b e t n e g a t i v e .61∗ @param b e t v a l u e o f a p o i n t62∗ @param s e l e c t e d L i n e s t h e l i n e s t h e p l a y e r wants t o b e t on .63∗ /64p u b l i c vo id s e t B e t ( i n t be t , P l a y L i n e [ ] s e l e c t e d L i n e s ) throws B e t E x c e p t i o n {65/ / TODO66}6768/∗∗69∗ @return t h e p l a y e r s c u r r e n t c r e d i t70∗ /71p u b l i c i n t g e t B a l a n c e ( ) {72re turn b a l a n c e ;73}7475/∗∗76∗ S e t t h e b a l a n c e .77∗ @param b a l a n c e new b a l a n c e v a l u e78∗ /79p u b l i c vo id s e t B a l a n c e ( i n t b a l a n c e ) {80t h i s . b a l a n c e = b a l a n c e ;81}8283/∗∗84∗ Add an amount ( e . g . from a win ) t o t h e b a l a n c e .85∗ @param amount i n c r e m e n t ( or decremen t )86∗ /87p u b l i c vo id addToBalance ( i n t amount ) {88b a l a n c e +=amount ;89}

18

Page 19: Informatie voor het proef assessment SEN1 op 18 juni 2010 · 2010. 6. 8. · Informatie voor het proef assessment SEN1 op 18 juni 2010 Dr. Ir. F. van Odenhoven & Ir. P. van den Hombergh

2 CODE LISTINGS 2.4 IconSlotMachine.java and Test

9091/∗∗92∗ Get a s h o r t s t a t u s message t o i n f o r m t h e p l a y e r93∗ /94p u b l i c S t r i n g ge tMessage ( ) {95re turn t h i s . r e s u l t M e s s a g e ;96}9798/∗∗99∗ Compute t h e c o s t o f a game100∗ @param p o i n t V a l u e wor th o f one p o i n t , m u l t i p l i e r101∗ @param l i n e s l i n e s t h e u s e r want t o b e t on102∗ /103p u b l i c i n t g e t C o s t ( i n t p o i n t V a l u e , P l a y L i n e [ ] l i n e s ) {104re turn l i n e s . l e n g t h∗p o i n t V a l u e ;105}106107/∗∗108∗ Get t h e J a c k p o t s t a t u s o f t h e l a s t P l a y F i e l d109∗ /110p u b l i c boolean i s J a c k P o t ( ) {111re turn game . i s J a c k P o t ( ) ;112}113114/∗∗115∗ Get t h e Value o f a l i n e f o r r a n k i n g p u r p o s e s116∗ @return t h e v a l u e o f t h e l i n e as an i n t .117∗ /118p u b l i c i n t g e t P l a y L i n e V a l u e ( P l a y L i n e l i n e ) {119re turn game . g e t P l a y L i n e V a l u e ( l i n e ) ;120}121122} /∗ e o f I c o n S l o t M a c h i n e . j a v a ∗ /

19