You are on page 1of 10

Laboratory Manual

Subject Name: Object Oriented Programming

Student Name

Reg. No.

Date

MAPPING OF LAB TO CLOs & PLOs


CLO 3: Design programs to solve computing problems PLO 3: Design/Development of
based on given requirements using principles of object- solution
oriented programming. Cognitive Domain: C6

Rubric for Design

Criteria Attainment Score

Excellent Very good Good Fair Poor

(100-85%) (84-71%) (70-61%) (60-50%) (49-0%)


Understandi Skillful ability Very good Good ability to Some ability to
Minimal
ng the Given to understand ability to understand and understand andability to
scenario and explain a understand explain a given explain a given
understand
given and explain a scenario. scenario. and explain a
scenario. given given
scenario. scenario.
Develop Skillful ability Very good Good ability to Some ability to Minimal
program to design or ability to design or design or ability to
according to develop design or develop develop design or
given computer develop computer computer develop
scenario programs. computer programs. programs. computer
programs. programs.
Generation Skillful ability Very good Good ability to Some ability to Minimal
and to ability to evaluate/confir evaluate/confir ability to
interpretatio evaluate/ evaluate/confir m the m the evaluate/confir
n confirm the m the functioning of functioning of m the
of functioning of functioning of the final code, the final code, functioning of
results the final code, the final code, with with the final code,
based with with deliberation deliberation for with
on deliberation for deliberation for for further further deliberation
scenario further further improvement. improvement. for further
s improvement. improvement. improvement.

Lab 1: Dealing with classes, methods, variables, and syntax in JAVA


General Syntax:
To write, compile and run the java program follow these steps

• Open NOTEPAD and type the following program.

• Save the program in any directory with the name UOL(same as the name of class ) and
Extension (.java) for example UOL.java
• Now compile the program that converts the java source code into binary program consisting of
byte codes.
• Assuming your program contains no errors, the compiler generates a byte code program that is
equivalent of your source code. The compiler stores the byte code program in a file with the
same name as source file, but with the extension .class. Java executable modules are always
stored in a file with the extension .class
• When you execute a java program a program called the Java interpreter inspects the byte code
for it checks it out to ensure that it has not been tempered and is safe to execute and then
execute the actions that the byte codes specify within the java virtual machine.
• If there is no exception in the program the output in printed

System.out.print command in java is same as cout in C++

Run the following programs and observe the output.

Program:
Program:

Variables and Data Types in Java

Variable is a name of memory location. There are three types of variables in java: local,
instance and static.

There are two types of data types in java: primitive and non-primitive.

Variable

Variable is name of reserved area allocated in memory. In other words, it is a name of memory
location. It is a combination of "vary + able" that means its value can be changed.
int data=50; //Here data is variable

Types of Variable
There are three types of variables in java:

Loca variable

instance variable

static variable

1. Local Variable
A variable which is declared inside the method is called local variable.

2. Instance Variable
A variable which is declared inside the class but outside the method, is called
instance variable. It is not declared as static.

3. Static variable
A variable that is declared as static is called static variable. It cannot be local.

Example to understand the types of variables in java


Data Types in Java
Data types represent the different values to be stored in the variable. In java, there are two types
of data types:

• Primitive data types


• Non-primitive data types
Operators in java

Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc.

There are many types of operators in java which are given below:

• Unary Operator,
• Arithmetic Operator,
• shift Operator,
• Relational Operator,
• Bitwise Operator,
• Logical Operator, • Ternary Operator and
• Assignment Operator.

In this lab we will cover only Arithmetic and Unary operator.

Type Casting

Assigning a value of one type to a variable of another type is known as Type Casting.
Example:

int x = 10; byte


y = (byte)x;

In Java, type casting is classified into two types,

• Widening Casting (Implicit)

Automatic or Widening Type casting take place when,

• the two types are compatible.


• the target type is larger than the source type

• Narrowing Casting (Explicitly done)

When you are assigning a larger type of value to a variable of smaller type, then you need to perform
explicit type casting.
Tasks:

1: Give your name and registration number as input and generate the output in interaction pane.

2: Test the results 36%10 and 36%40, 36/40 & 36/10, 6.0/4 & 6/4? What is the cube of 36?

3: Calculate the average, sum & difference of 876 & 767.First stores these values in proper
type, then calculate the result.

4: Calculate the circumference and area of the circle of radius 0.5 km. Circumference=2*pi *r.
Area= * r 2

5: Write a program to assign three values to three integer type variables a, b and c. Add
variables a and b and multiply their sum to variable c. Use compound assignment statement.

6: Write a program to perform an implicit and explicit type casting.


Lab Assessment

Understanding the Develop program Generation and


Given scenario according to given interpretation of
(Criteria 1) scenario results based on Total
(3) scenarios
(Criteria 2) 15 Marks
(5) (Criteria 3)
(7)

Task 1

Task 2

Task 3

Task 4

Task 5

Task 6

Average
Marks

Lab Engineer Name: Engr. Muhammad Zafar Signature: ___________________

You might also like