0% found this document useful (0 votes)
3 views

q.Object modelling

The document outlines the process of object modeling, specifically using the example of a deck of cards. It details steps such as system analysis, design, and implementation, along with code snippets for generating, displaying, and shuffling a deck of cards. The document emphasizes the importance of visualizing application elements as objects in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

q.Object modelling

The document outlines the process of object modeling, specifically using the example of a deck of cards. It details steps such as system analysis, design, and implementation, along with code snippets for generating, displaying, and shuffling a deck of cards. The document emphasizes the importance of visualizing application elements as objects in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

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!

Object Model of Deck of


Cards

Step 1: System Analysis

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;

for (int i = 0; i < 4; i++)


{
for (int j = 0; j < 13; j++)
{
deck[SUITS.length*j + i] = RANKS[j] + " of " + SUITS[i];
}
}
}
To shuffle !

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)
{

System.out.println(RANKS[j] + " of " +


SUITS[i]);
}
public class Function extends Card
void shuffle() {
{
// shuffle public static void main(String args[])
for (int i = 0; i < n; i++) {
{ Card C=new Card();
int r = i + (int) (Math.random() * (n-i)); for (int i = 0; i < 4; i++)
String temp = deck[r]; {
deck[r] = deck[i]; for (int j = 0; j < 13; j++)
deck[i] = temp; {
} C.disp(i,j);
for (int i = 0; i < n; i++) }
{ }
System.out.println(deck[i]); C.Initialize();
} C.shuffle();
} }
}
OUTPUT
Thank you!

You might also like