Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab Questions: Presented By: Tekendra Nath Yogi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Lab Questions

Presented By : Tekendra Nath Yogi


Tekendranath@gmail.com
College Of Applied Business And Technology
Lab1
• Write a Java program to display Hello world message on the Console.

• Write a Java program to find the sum of two number.

• Write a Java program to find the Simple interest.

• Write a Java program to find the area and perimeter of a rectangle.

• Write a Java program to find area and perimeter of a circle.

• Write a Java Program to Check Whether a Number is Even or Odd

• Write a java program to Swap Two Numbers

• Write a java program Java Program to Check Whether a Number is Positive or


Negative.

• Write a Java Program to Find the Largest Among Three Numbers.

11/23/2021 By: Tekendra Nath Yogi 2


Lab2
• Write a Java Program to Calculate the Sum of first n Natural Numbers

• Write a Java Program to Calculate sum and Average of Array elements.

• write a java program to find max and min value from array of size 10.

• Write a java program to decide whether the input year is leap year or not (A
year is leap, if it is divisible by 4 and 400. But, not by 100.).

• Write a Java program to decide the grade of a student based on the marks
obtained by a student.

• Write a Java program to decide whether a person is eligible to donate a blood or


not ( a person is eligible to donate a blood if his age>=18 and weight>=50 kg).

• Write Java program to search a number in a array. If found return the index.

• Write a java program to find the sum of array elements. Except the element at
index position 5.
11/23/2021 By: Tekendra Nath Yogi 3
Lab 2
• Write a java program to find the sum of array elements. If negative element is
found return the sum of previous elements of the array.

• Write a Java Program to Count Number of Digits in an Integer.

• Write a program to find the sum of the digits of a given integer number.

• Write a Java Program to Reverse a Number.

• Write a java program to check palindrome number.

• Write a java program to print factorial of a number.

• Write a java program to check Armstrong number.

• Write a Java program to find the GCD of two Numbers.

• Write a Java Program to Make a Simple Calculator Using switch...case

11/23/2021 By: Tekendra Nath Yogi 4


Lab 2
• Write a java program to read the price of an item in decimal form (like 75.95)
and print out the output in Paisa (like 7595 Paisa).

• Write a program to convert the given temperature in Fahrenheit to Celsius using


the following conversion formula (C=(F-32)/1.8).

• Write a program with two arrays called height and weight for persons and then
count the numbers of persons with height>170 and weight<50.

• Write a program to count the number of evens and odds in a array.

• Write a program to find the number and sum of all integers greater than 100 and
less than 200 that are divisible by 7.

• Write a program to display the Floyd’s triangle.

11/23/2021 By: Tekendra Nath Yogi 5


Lab 3
• Write a java program to illustrate the concept of class and object.
• Write a java program to illustrate the concept of constructors in java
• Write a java program to find the sum of different types of data by using the concept of
method overloading.
• Write a java program to find the area and volume of cube box and normal box by using
the concept of constructor overloading.
• Write a java program to illustrate the concept of call by value in Java.
• Write a java program to illustrate the concept of call by reference in Java.
• Write a java program to illustrate the concept of this keyword in Java.
• Write a java program to illustrate the concept of static data members and static member
functions in Java.
• Write a Java program to illustrate the passing and return object from the method.
• Create a Java program with a class and a driver class. Create the object of the class in a
driver class and access the fields using dot operator.
• Create a Java program with a class and a driver class. Create the object of the class in a
driver class and access the fields using member function
• Create a Java program with a class and a driver class. Create the object of the class in a
driver class and use the constructor to initialize the object automatically.
11/23/2021 By: Tekendra Nath Yogi 6
Lab 3
• Write a java program with a Student class which has two data members id and name.
Then create the object of the Student class by new keyword and printing the object's
value. (Initialize the data members by reference, by member function, by constructor)
Write different program for each case.

• Write a java program with a Employee class which has two data members id, name, age
and salary. Then create the object of the Employee class by new keyword and printing
the object's value. (Initialize the data members by reference, by member function, by
constructor) Write different program for each case.

• Write a Java program with a Rectangle class which has two data members length and
breadth. Use this class to find the area and perimeter of a rectangle.

• Write a Java program to demonstrate the working of a banking system where we deposit
and withdraw amount from your account. Create an Account class which has deposite( )
and withdraw( ) methods.
11/23/2021 By: Tekendra Nath Yogi 7
Lab 3
• Create a class Named Student with default constructor and parameterized constructors.
Use the constructors while making its object as pass a name of it and if nothing is
passed, then name should be "unknown". And finally display the name of student using
the printName( ) method.

• Write a Java program with a class named Box with data members length, breadth and
height of box, use constructor to set the value of these data members and use member
functions area, and volume to calculate the area and volume of corresponding box.

• Write a Java program with a class named Room with data members length, breadth and
height of box, use constructor to set the value of these data members and use member
functions area, and volume to calculate the area and volume of corresponding Room.

• Create a class named 'Student' with String variable 'name' and integer variable 'roll_no'.
Assign the value of roll_no as '2' and that of name as "John" by creating an object of the
class Student.
11/23/2021 By: Tekendra Nath Yogi 8
Lab 3
• Assign and print the roll number, phone number and address of two students having
names "Sam" and "John" respectively by creating two objects of class 'Student'.
• Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5
units by creating a class named 'Triangle' without any parameter in its constructor.
• Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5
units by creating a class named 'Triangle' with constructor having the three sides as its
parameters.
• Write a program to print the area of two rectangles having sides (4,5) and (5,8)
respectively by creating a class named 'Rectangle' with a method named 'Area' which
returns the area and length and breadth passed as parameters to its constructor.
• Write a program to print the area of a rectangle by creating a class named 'Area' having
two methods. First method named as 'setDim' takes length and breadth of rectangle as
parameters and the second method named as 'getArea' returns the area of the rectangle.
Length and breadth of rectangle are entered through keyboard.
• Add two distances in inch-feet by creating a class named 'AddDistance'.
• Print the sum, difference and product of two complex numbers by creating a class named
'Complex' with separate methods for each operation whose real and imaginary parts are
entered by user.

11/23/2021 By: Tekendra Nath Yogi 9
Lab 3
• Write a program to print the area of a rectangle by creating a class named 'Area' taking
the values of its length and breadth as parameters of its constructor and having a method
named 'returnArea' which returns the area of the rectangle. Length and breadth of
rectangle are entered through keyboard.

• Print the average of three numbers entered by user by creating a class named 'Average'
having a method to calculate and print the average.

• Write a Java program with a class Named Arithmetic (two integer numbers as its data
member and member functions for each arithmetic operation). Create objects of this
class and perform the various arithmetic operations on the data of each object.

11/23/2021 By: Tekendra Nath Yogi 10


Lab 4
• Write a Java program to illustrate the single Inheritance.

• Write a Java program to illustrate the Multi-level Inheritance.

• Write a Java program to illustrate the Hierarchical Inheritance.

• Write a Java program to illustrate method overriding.

• Write a Java program to illustrate the different uses of final keyword.

• Write a Java program to illustrate the order of execution of constructors in the


case of Inheritance.

• Write a Java program to call a super class constructors from the sub-class
constructor.

11/23/2021 By: Tekendra Nath Yogi 11


Lab 5
• Write a Java program to create and extend the interface.

• Write a Java program to create and implement the interface.

• Write a Java program implementing multiple inheritance by using interface


mechanism.

• Write a Java program to create a package, use the classes in the user defined
packages.

• Write a Java program to illustrate the use of private access modifier.

• Write a Java program to illustrate the use of Public access modifier.

• Write a Java program to illustrate the use of Protected access modifier.

11/23/2021 By: Tekendra Nath Yogi 12


Lab 6
• Write a program using try and catch block to handle exceptions. Also display the
exception information on the console.

• Write a program with multiple catch blocks that are used to handle exceptions generated
by a single block of code.

• Write a program to illustrate the use of finally block in exception handling .

• Write a program to illustrate the use of throw keyword to throw the exception explicitly.

• Write a program to illustrate the use of throws in exception handling.

• Write a program to throw your own exception (i. e. user define exception) and handle it.

• Write a java program to illustrate the nested try blocks.

• Write a java program to validate the age entered by user if age is more than 18 and
display appropriate message other wise throw an exception object with message “invalid
age” and display the message in exception object by the handler.(throw system
exception, throw custom exception).
11/23/2021 By: Tekendra Nath Yogi 13
Lab 6
• Write a java program with try catch block. Enclose the code that may generate
ArithmeticException in try block and resolve the exception in catch block.

• Write a java program to check student eligibility for registration. If student age is less
than 12 and weight is less than 40 then the student should get an ArithmeticException
with the warning message “Student is not eligible for registration”, other wise student
should get Student Entry is Valid message. throw the exception using throw keyword.

• Write a Java program to throw custom exception explicitly using throw keyword in
combination with throw keyword in combination with throws keyword when employee
age is negative.

• Write a Java program to illustrate the exception propagation using throws keyword.

• Write a Java program to illustrate the handling of checked exceptions in Java.

• Write a Java program to illustrate the handling of unchecked exception in Java.

11/23/2021 By: Tekendra Nath Yogi 14


Lab 6
• Create a class Student with attributes roll no, name, age and course. Initialize values
through parameterized constructor. If age of student is not in between 15 and 21 then
generate user-defined exception "AgeNotWithinRangeException". If name contains
numbers or special symbols raise exception "NameNotValidException". Define the two
exception classes.

• Create a CheckingAccount class containing deposit() and withdraw() method that throws
an InsufficientFundsException in case of withdraw if the amount to be withdrawn is
greater than the total amount in the account..

• Define an exception called “NotMathchException” that is thrown when a string in not


equal to “Nepal”. Write a program that uses this exception.

11/23/2021 By: Tekendra Nath Yogi 15


Lab 7
• Write a Java Program to copy all elements of one array into another array.

• Write a Java Program to find the frequency of each element in the array.

• Write a Java Program to print the duplicate elements of an array.

• Write a Java Program to print the elements of an array.

• Write a Java Program to print the elements of an array in reverse order.

• Write a Java Program to print the elements of an array present on even position.

• Write a Java Program to print the elements of an array present on odd position.

• Write a Java Program to print the largest element in an array.

• Write a Java Program to print the smallest element in an array.

• Write a Java Program to print the number of elements present in an array.

• Write a Java Program to print the sum of all the items of the array.

• Write a Java Program to right rotate the elements of an array.


11/23/2021 By: Tekendra Nath Yogi 16
Lab 7
• Write a Java Program to sort the elements of an array in ascending order.

• Write a Java Program to sort the elements of an array in descending order.

• Write a Java Program to find Largest Number in an Array.

• Write a Java Program to find 3rd Largest Number in an Array.

• Write a Java Program to find 2nd Largest Number in an Array.

• Write a Java Program to find 2nd Smallest Number in an Array.

• Write a Java Program to find Smallest Number in an Array

• Write a Java Program to remove Duplicate Element in an Array.

• Write a Java Program to Add Two Matrices.

• Write a Java Program to Multiply Two Matrices.

• Write a Java Program to Print Odd and Even Number from an Array.

• Write a Java Program to Transpose matrix.


11/23/2021 By: Tekendra Nath Yogi 17
Lab 7
• Write a Java Program to subtract the two matrices.

• Write a Java Program to determine whether a given matrix is an identity matrix.

• Write a Java Program to determine whether a given matrix is a sparse matrix.

• Write a Java Program to determine whether two matrices are equal.

• Write a Java Program to find the frequency of odd & even numbers in the given matrix.

• Write a Java Program to find the product of two matrices.

• Write a Java Program to find the sum of each row and each column of a matrix.

• Write a Java Program to find the transpose of a given matrix.

• Write a java program to check the equality of two strings.

• Write a java program to find the sub-string Ram in the string HariRamBahadur.

11/23/2021 By: Tekendra Nath Yogi 18


Thank You !

11/23/2021 By: Tekendra Nath Yogi 19

You might also like