Professional Documents
Culture Documents
• implementation – DO it
Possibly
Problem description
Use-case descriptions
• Which classes and objects are needed, and how they will
interact
UI Design
• How will it look like? How the system will interact with the
user?
Maintenance
// header
String name;
public class Person { int age;
double salary;
String comments;
// properties
Always
• Declare variable to “hold” object
• Create object using “new”
statement
• Call object’s methods
Person aStudent;
aStudent = new Person( “Ayse”, 18);
aStudent.sayName(); name: “Ayse”
age: 18
aStudent
Put this in method {Person} salary: 0.0
of another class, comments:
(e.g main “”
method)
Person aStudent;
aStudent = new Person( “Ayse”, 18);
Person friend;
friend = new Person( “David”, 22);
name: “David”
age: 22
23
name: “Ayse”
salary: 0.0
age: 18
aStudent friend comments:
{Person} salary: 0.0 {Person} “”
comments:
“”
“Good student”
friend.increaseAge();
aStudent.setComments( “Good student”);
* by David Davenport
Copyright © 2014 by John Wiley & Sons. All rights reserved. 13
Example: A Card Game
Objects player
the Game?
Pack of cards
Players 1, 2, 3 & 4
score
the Table?
Score card? player player
(Player 1, 2, 3 Table
& 4 scores) score score
Players 1, 2, 3 & 4 Cards
on table score
Players 1, 2, 3 & 4 Cards
player
in hand
Pack of cards
CleverGame Player
Pack of cards Name
4 Players Set of cards in hand
Scorecard
(with 4 scores on)
4 Piles of cards Cards
on table Collection of cards
ScoreCard Card
Set of scores
Face value
Suit
Represents a single
properties card game played by
Pack of cards, 4 Players 4 players
ScoreCard, 4 Piles of cards on table
constructor ( 4 players)
creates the game with the given players
Methods
+ playTurn(Player, Card) : boolean
+ isTurnOf(Player) : boolean
+ isGameOver() : boolean
+ getScore( playerNumber) : int
+ getName( playerNumber) : String
+ getRoundNo() : int
+ getTurnOfPlayerNo() : int
+ getWinners() : set of Player
constructor ( name)
creates player with name & empty hand
methods
getName()
returns players name
add( Card)
add the card to players hand
playCard()
removes and returns the top card from the players hand
properties Represents a
Set of scores ScoreCard for a card
game
constructor ( noOfScores)
initialises scorecard with noOfScores entries all set to zero
methods
+ getScore(scoreNo) : int
returns specified score
+ update( scoreNo, amount)
add amount to scoreNo
methods
getTopCard()
removes & returns top card from collection
addTopCard( Card)
adds the card to the collection
createFullPackOfCards()
shuffle()
randomises order of cards in collection
properties
faceValue
Represents a single
playing card
suit
methods
getFaceValue()
returns faceValue
getSuit()
returns suit
toString()