Cmp712 Lab Java - Programming
Cmp712 Lab Java - Programming
Practical 1:
Activities:
1. Write a Java class to swap two numbers without using third variable.
2. Write a Java Program to determine reverse the number
3. Write a Java class to print the Fibonacci sequence till100
4. Write a Java Program to determine whether the number is Armstrong or not.
5. Write a Java Program to determine whether the number is prime or not.
-----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
Practical 2:
Activities
1. Write a Java program for the following scenario: Run a loop from 1 to 100, while looping
when the number is even print its square and when the number is odd print its cube.
2. Write a Java program to print the following Floyd Triangle
1
01
1 01
0 1 01
3. Write a Java Program to print following
12345
1234
123
12
1
----- ---------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
Practical 3:
Activities :
1. Write a Java class Employee with variables name, age, gender write setter and getter
2. Write a class mobile with methods call() and sms(). Write a class Demo and accessit.
3. Write a class MathDemo with methods square() with one parameter and add() with two
--------------------------------------------------------------------------------------------------------------------
----- ---------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
Practical 4:
Activity 1: Write a Java class for following methods
1. Display() -- Display number from 1 to 100 using while loop in Java
2. Fibonacci() -- Prints Fibonacci series till 100.
-------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
Practical 5:
Activity 1: Write a class Automobile with default constructor, write a class Plane which extends
Automobile and has a default as well as parameterized constructor, write a class Airbus with a default
constructor which extends Plane.
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Practical 6:
Activities
1. Write a Java Program to convert “25” to Primitive as well as Wrapper.
2. Write a Java program to convert 110011 to decimal value
.-------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
Practical 7:
Activity 1: Write a Java Program to convert the “59” to Primitive float (without using Constructor
of Float)
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Practical 8:
Activity 1: Write a class User with abstract methods pay() and receive(), later make two concrete
class GoldUser and SilverUser, override the abstract method
.-------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Practical 9:
Activity 1: Write a Java program to write the following, class A with method m1( ) and m2( ) and
write a class B with methods m3( ) and m4( ),Override the methods of A in class B.
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
Practical 10:
Activities
1. Write an abstract class Car with methods start() and stop(). Write a class Santro and Audi and
override the methods.
2. Write two interfaces SportsCar and Commercial Car and implement the appropriate interface on
the appropriate class made in example 1.
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Practical 11:
Activities:
1. Make an Interface CE which have methods call(), sms (), Make another interface ISO which have
methods radiation() and sound(). Make two classes IPhone and Galaxy and make them
implement both the interfaces.
2. Write a Java program to make a package com. shapes, make classes Circle and Square in the
same package
.-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Practical 12:
Activities
1. Write a Java Program to make an Exception AgeException. When user passes some age and if
age is less than 18 throw this Exception.
2. Create an Exception StringNotPalindromeException. Write a class with method which throws this
Exception when String passed is not palindrome.
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
Practical 13:
Activities:
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
Practical 14:
Activities :
1. Write a Java Program to store the following data, in the collection you feel will suitebest.
Name- Tom
Email- [email protected]:9988776655
2. Write a Java Program to find the minimum value in Vector [8,9,1,3,4].
3. Write a Java Program to find the number of String starting with „S‟ from following
TreeSet [ Smith, Alex , Tom, Steve, Mark, Sammy]
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
Practical 15:
Activity 1: Sort the given list of objects in order of their email Contact: id, name, email, phone
-----------------------------------------------------------------------------------------------------------------
________________________________________________________________________
---------------------------------------------------------------------------------------------------------------------
---- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--- -----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------