Lab 2
Lab 2
OBJECTIVE NO:
Objective
1.1 Introduction
1|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
1. 1.1b Naming Convention: The convention, however, is to always begin your variable
names with a letter, not "$" or "_". If the name you choose consists of only one word, spell
that word in all lowercase letters. If it consists of more than one word, capitalize the first
letter of each subsequent word.
• Example. int average=0; float temperature=1.8f; int currentGear=1; and e.t.c
It is conversion of real number value to integer value and integer to real number value.
2|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
2) Explicit casting also known as forceful conversion. It is conversion of real value into
integer number value, it is forcefully implemented.
Example: int Age = (int) 2.314;
1.1.4 Operators:
These are some symbols or special characters which specify some specific operation.
1. Type of operation.
2. Numbers of operands.
Number of
Operators Symbols Operands Uses
3|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
Output
4|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
Output
5|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
Output
2. 4 Operators (Example).
Output
6|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
7|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
OBJECT OREINTED PROGRAMMING
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 2
Exercise
[60 minutes]
Q.1 Write a java program that asks the user to enter two numbers and print the largest one.
Q.3 Average acceleration is defined as the change of velocity divided by the time taken to
make the change, as shown in the following formula:
𝑣1−𝑣0
𝑎=
𝑡
Write a program that prompts the user to enter the starting velocity v0 in meters/ second, the ending
velocity v1 in meters/second, and the time span t in seconds, and displays the average acceleration.
Q.4 Write a program that prompts the user to enter his/her monthly salary and computes
the bonus.
The bonus is 1000/= PKR plus 2% of the amount above 7000/=PKR of the employee’s annual
salary. Assume that every employee has annual salary above 7000/= PKR
Q. 5 Write a program that prompts the user to enter some amount in PKR, determines the number
of 5000 Rs. notes, 1000 Rs. notes, 500 Rs. notes, 100 Rs. notes, and 1 Rs. Coins for the given
amount.
8|Page