q.Object modelling
q.Object modelling
Lecture 20
Object
Object Modeling
Plan according to
noun Goal or Reason verb
reach the goal!
Visualizing elements in
applications in the form of
Object Modeling objects
Steps in Object modeling!
System analysis
System design
Object design
Implementation
Let’s take a simple example!
Problem
Problem statement : generate and display the deck of cards value
statement
Card display
Class Deck:
Class Card:
Call to generate the
Generate the cards
cards
Suit : Spades
Hearts Face
FaceValue
Value::Ace
10
"Hearts",
"Clubs",
Suit value "Diamonds",
4 "Spades"
Card "Ace",
"2",
"3",
"4",
Face value "5",
13 "6",
"7",
"8",
"9",
"10",
"Jack","Queen","King"
//create arrays for card labels
String[] SUITS =
{
"Clubs", "Diamonds", "Hearts", "Spades"
};
String[] RANKS =
{
"2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"
};
int n = 4 * 13;
String[] deck = new String[n];
For a single card!
class Card
{
void disp(int i,int j)
{
System.out.println(RANKS[j] + " of " + SUITS[i]);
}
};
But it should be done for all the 52 cards!!
Therefore
public class Function extends Card
{
public static void main(String args[])
{
Card C=new Card();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 13; j++)
{
C.disp(i,j); Call the Card class to print every single card!!
}
}
} This is to display the deck
of cards!
}
To shuffle the cards! 1. Initialize an array and
store the deck of cards
2. Shuffle the cards
To initialize !
void Initialize()
{
//int n = 4 * 13;
void shuffle()
{
// shuffle
for (int i = 0; i < n; i++)
{
int r = i + (int) (Math.random() * (n-i));
String temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
for (int i = 0; i < n; i++)
{
System.out.println(deck[i]);
}
}
Therefore
public class Function extends Card
{
public static void main(String args[])
{
Card C=new Card();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 13; j++)
{
C.disp(i,j); Call the Card class to print every single card!!
}
}
} This is to display the deck
C.Initialize(); of cards!
C.shuffle();
}
void Initialize()
class Card {
{ //int n = 4 * 13;
public
String[] SUITS = for (int i = 0; i < 4; i++)
{ {
"Clubs", "Diamonds", "Hearts", "Spades" for (int j = 0; j < 13; j++)
}; {
deck[SUITS.length*j + i] =
String[] RANKS = RANKS[j] + " of " + SUITS[i];
{ }
"2", "3", "4", "5", "6", "7", "8", "9", "10", }
"Jack", "Queen", "King", "Ace" }
};
int n = 4 * 13;
String[] deck = new String[n];
void disp(int i,int j)
{