Republic of the Philippines
BATANGAS STATE UNIVERSITY
BatStateU Pablo Borbon Main II
Alangilan, Batangas City
College of Engineering, Architecture and Fine Arts
https://batstate
- u.edu.ph/, Tel. No. (043) 425 -0139 loc. 118/2121
ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT
Object-Oriented Programming
I. OBJECT ORIENTED DESIGN USING UML
1.1 Student Outcomes (SO/s)
SO 6: An ability to develop and conduct appropriate experimentation, analyze and
interpret data, and use engineering judgment to draw conclusions.
1.2 Intended Learning Outcomes (ILO/s)
At the end of this activity, the student shall be able to: a.
defines terms
b. Review on the concept of design objects with responsibilities.
1.3 Objectives of the Activity
The objectives of this activity are to:
a. Understand the concept of OOP analysis and design using UML.
b. Discuss the nature and relationship of objects.
c. Discuss the nature and interplay of classes and objects.
d. Identify classes and objects.
e. Know the importance of proper classifications.
1.4 Principle of the Activity Object
Objects have a behavior that is expressed in terms of operations. The execution of
operations changes the stack of the objects and/or stimulates the execution of
operations in other objects.
Objects have an origin in a real-world entity
Classes
Classes represent groups of objects which have the same behavior and information
structures.
1. Every object is an instance of a single class.
2. Class is a kind of type, an ADT or an entity.
3. Classes are the same in both analysis and design.
Relationships among Objects
Two kinds of objects relationships
• Links
• Aggregation
Links:
Specific Association through which one object applies services of another object.
As a participation in a link, an object may play one of three roles.
• Controller – Operates another object.
• Server – Operated by another object.
• Pray – Both operates and operated by objects
Relationships among Classes
There are three basic kinds of class relationships.
1. Generalization / specification, denotes ‘is – a’ relationship. The symbol for
generalization is
2. Aggregation / whole / part of relationship. The symbol for aggregation is
3. Association, which denotes semantics dependency among unrelated classes. The
symbol for association is
Association:
- The identification of association among classes is describing how many classes /
objects are taking part in relationship.
Multiplicity/Cardinality:
- The multiplicity denotes the cardinality of the association. There are three
common kinds of multiplicity across an association.
One – to – One
One – to – Many
Many – to - Many
.
1.5 Materials/Equipment
Computer Unit
1.6 Procedure/s
1. Create a class diagram for this scenario.
• A house may have any number of pets living in it.
• The two possible types of pets that can live in a house are dogs and cats.
• Each dog or cat has a name. • An animal’s house is its one and only home.
• You can tell an animal to make noise and it will do its thing.
2. Create the diagrams as describe below and include discussion to each diagram.
a. Use Case diagram, describe how to play chess via an interface able to
connect either different engines or a chess server via internet.
b. Class diagram, describe the pieces, chessboard and the game tree.
c. Object diagram, describe by object snapshots a chess position during a
game.
NOTE: Use the Activity Report Section for your solution.
1.7 Activity Report
Section: CpE - 2201 Date Performed:
Course Code: CPE 406 Date Submitted:
Course Title: OBJECT ORIENTED PROGRAMMING
Instructor: ENGR. ERWIN S. COLIYAT
Group No.: 6 Activity No.: 1
Name: Vince Patrick Aclan Signature:
John Mico Dela Cruz
Arjay Gamboa
Janssen Hayag
Junnel Malabanan
(1) Class Diagram
(2a) Case Diagram: Chess Game
(2b) Class Diagram: Chess Game
(2c) Object Diagram: Chess Game
1.8 Rating
Criteria Grade
Activity Conduct (1-5)
Correctness of Command(s)/Program(s) (1-5) x 2
Completeness of Tasks (1-5)
Data Analysis and Results Interpretation (1-5)
Total Score
Mean Score = (Total Score / 5)
Percentage Score = (Total Score/25) * 100
Other Comments:
II. ARRAYS
1.2 Student Outcomes (SO/s)
SO 6: An ability to develop and conduct appropriate experimentation, analyze and
interpret data, and use engineering judgment to draw conclusions.
1.2 Intended Learning Outcomes (ILO/s)
At the end of this activity, the student shall be able to: c.
Define terms
d. Review on the concepts of arrays.
1.3 Objectives of the Activity The
objectives of this activity are to:
f. Understand the concept of Arrays.
g. Discuss array declaration, initialization and storing values to an array.
h. Discuss multi-dimensional Array.
1.4 Principle of the Activity
An ARRAY is like a container that holds a fixed number of values of a particular type.
Memory space is allocated for values of similar type during array declaration. The length
of the array is specified and remains constant at the time it was created.
Benefits in using Array
• In a large group of elements, a particular element can be accessed easily using the
array name and the element index.
• Arrays are useful in executing calculations within a loop.
How to declare an Array
<data type> [ ] <array name>
Example:
int[ ] arrayNumbers;
String[ ] arrayNames;
char[ ] arrayLetters; double[
] arrayDouble;
float[ ]arrayValue;
We can also write it this way:
int arrayNumbers [ ];
How to initialize and create an Array
//create an array of integers
arrayNumbers = new int[5];
this indicates that arrayNumbers have a length of 5, meaning the array is capable of
holding or storing 5 integers.
//assign values to each element of the arrayNumbers
arrayNumbers[0]=10; // initialize the first element
arrayNumbers[1]=120;//initialize the second element
arrayNumbers[2]=30;//initialize the 3 element
rd
arrayNumbers[3]=80;//initialize the 4 element
th
arrayNumbers[4]=100;//initialize the 5 element
th
The array index will always start with index of zero [0]. In this case the elements of
arrayNumbers are 10,120,30,80 and 100.
1.5 Materials/Equipment
Computer Unit
1.6 Procedure/s
1. Create a Java program using Array to display the required output.
Output:
Enter 10 integers.
Num 1=10
Num 2=50
Num 3=30
Num 4=80
Num 5=70
Num 6=20
Num 7=90
Num 8=40
Num 9=60
Num 10=100
Display the elements of array
MyNum[0]=10
MyNum[1]=50
MyNum[2]=30
MyNum[3]=80
MyNum[4]=70
MyNum[5]=20
MyNum[6]=90
MyNum[7]=40
MyNum[8]=60
MyNum[9]=100
Total=550
2. Create a Java program that will store all even numbers to one array (Even[]), then all
odd numbers (Odd[]) to another array.
int
MyNumbers[10]={1,2,3,4,5,6,7,8,9,10}
then display the content or elements of
Even[] and Odd[].
NOTE: Use the Activity Report Section for your solution.
1.7 Activity Report
Section: CpE - 2201 Date Performed:
Course Code: CPE 406 Date Submitted:
Course Title: OBJECT ORIENTED
PROGRAMMING
Instructor: ENGR. ERWIN S. COLIYAT
Group No.: 6 Activity No.: 1
Name: Vince Patrick Aclan Signature:
John Mico Dela Cruz
Arjay Gamboa
Janssen Hayag
Junnel Malabanan
(1) Array
Source Code:
import java.util.Scanner;
public class LAB3 {
public static void main(String[] args)
{ int[] list = new int[10];
Scanner input = new Scanner(System.in);
for(int i = 0; i<10; i++){
System.out.print("Enter the integer: ");
int x = input.nextInt();
list[i] = x;
}
System.out.println(" ");
for(int a = 0; a<10; a++){
System.out.println("myNum[" + a + "]" + " = " + list[a]);
} int sum = 0;
for(int num:list){
sum = sum+num;
}
System.out.print("Total = " + sum);
}
}
Result:
(2) Array
Source Code:
public class Lab10 { public static void
main(String[] args) { int[]
a={1,2,3,4,5,6,7,8,9,10}; int odd[] =
new int[10]; int even[] = new int[10];
int j = 0, k = 0;
for(int i = 0; i < 10; i++)
{
if(a[i] % 2 != 0)
{ odd[j] =
a[i]; j++;
} else {
even[k] = a[i];
k++;
}
}
System.out.print("Odd[]: ");
if(j > 1) {
for(int i = 0;i < (j-1); i++)
{
System.out.print(odd[i]+ " ");
}
System.out.print(odd[j-1]);
}
System.out.println("");
System.out.print("Even[]: ");
if(k > 1)
{
for(int i = 0; i < (k-1); i++)
{
System.out.print(even[i]+" ");
}
System.out.print(even[k-1]);
}
System.out.println("");
System.out.print("myNumbers[]: "); for(int
z = 0; z<10; z++){ System.out.print(a[z] +
" ");
}
}
}
Result:
1.8 Rating
Criteria Grade
Activity Conduct (1-5)
Correctness of Command(s)/Program(s) (1-5) x 2
Completeness of Tasks (1-5)
Data Analysis and Results Interpretation (1-5)
Total Score
Mean Score = (Total Score / 5)
Percentage Score = (Total Score/25) * 100
Other Comments: