3 - Sem - Bcs306a - Oop With Java - Lab - Manual - 2023-24
3 - Sem - Bcs306a - Oop With Java - Lab - Manual - 2023-24
3 - Sem - Bcs306a - Oop With Java - Lab - Manual - 2023-24
CHOICE BASEDCREDITSYSTEM
MISSION
• The Computer Science and Engineering department strives for excellence in teaching,
applying, promoting and imparting knowledge through comprehensive academic curricula.
• Train students to effectively apply the knowledge to solve real-world problems, thus enhance
their potential for life-long high-quality career and give them a competitive advantage in the
ever-changing and fast paced computing.
• Prepare students to demonstrate a sense of societal and ethical responsibilities in their
professional endeavors.
• Creating amongst students and faculty a collaborative environment open to the free exchange
of ideas, which leads to research activity and fuels innovation thinking.
PROGRAM OUTCOMES
PO's PO Description
Engineering knowledge: Apply the knowledge of mathematics, science, engineering
PO1 fundamentals, and an engineering specialization to the solution of complex
engineering problems.
Problem analysis: Identify, formulate, review research literature, and analyze
PO2 complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs
PO3
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and
PO4 research methods including design of experiments, analysis and interpretation of
data, and synthesis of the information to provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and
PO5 modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge
PO6 to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
Environment and sustainability: Understand the impact of the professional
PO7 engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and
PO8
responsibilities and norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a member
PO9
or leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as, being able to
PO10
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
Project management and finance: Demonstrate knowledge and understanding of
the engineering and management principles and apply these to one’s own work, as a
PO11
member and leader in a team, to manage projects and in multidisciplinary
environments.
Life-long learning: Recognize the need for, and have the preparation and ability to
PO12 engage in independent and life-long learning in the broadest context of technological
change.
1. Develop a JAVA program to add TWO matrices of suitable order N (The value of N should be
read from command line arguments).
import java.util.Scanner;
class AddMatrix
{
public static void main(String args[])
{
int row, col,i,j;
Scanner in = new Scanner(System.in);
System.out.println();
}
System.out.println("Enter the elements of matrix2");
System.out.println();
}
System.out.println("Sum of matrices:-");
System.out.println();
}
}
}
2. Develop a stack class to hold a maximum of 10 integers with suitable methods. Develop a JAVA
main method to illustrate Stack operations.
class Stack {
// Creating a stack
Stack(int size) {
// initialize the array
// initialize the stack variables
arr = new int[size];
capacity = size;
top = -1;
}
// if stack is empty
// no element to pop
if (isEmpty()) {
System.out.println("STACK EMPTY");
// terminates the program
System.exit(1);
}
return arr[top--];
}
stack.push(1);
stack.push(2);
stack.push(3);
System.out.print("Stack: ");
stack.printStack();
}
}
3.A class called Employee, which models an employee with an ID, name and salary, is designed as
shown in the following class diagram. The method raiseSalary (percent) increases the salary by the
given percentage. Develop the Employee class and suitable main method for demonstration.
4. A class called MyPoint, which models a 2D point with x and y coordinates, is designed as
follows:
// Default constructor
public MyPoint() {
this.x = 0;
this.y = 0;
}
// Overloaded constructor
public MyPoint(int x, int y) {
this.x = x;
this.y = y;
}
///////////////////////////
System.out.println("Distance from Point 1 to (5, 2): " + point1.distance(5, 2)); // Output: 7.6157...
5. Develop a JAVA program to create a class named shape. Create three sub classes namely:
circle, triangle and square, each class has two member functions named draw() and
erase (). Demonstrate polymorphism concepts by developing suitable methods, defining
member data and main program.
shape2.draw();
shape2.erase();
shape3.draw();
shape3.erase();
}
}class Shape {
public void draw() {
System.out.println("Drawing a shape");
}
@Override
public void erase() {
System.out.println("Erasing a circle");
}
}
@Override
public void erase() {
System.out.println("Erasing a triangle");
}
}
@Override
public void erase() {
System.out.println("Erasing a square");
}
}
6. Develop a JAVA program to create an abstract class Shape with abstract methods
calculateArea() and calculatePerimeter(). Create subclasses Circle and Triangle that extend
the Shape class and implement the respective methods to calculate the area and perimeter of
each shape.
@Override
double calculateArea() {
return Math.PI * radius * radius;
}
@Override
double calculatePerimeter() {
return 2 * Math.PI * radius;
}
}
@Override
double calculateArea() {
// Using Heron's formula to calculate the area of a triangle
double s = (side1 + side2 + side3) / 2;
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
@Override
double calculatePerimeter() {
return side1 + side2 + side3;
}
}
rectangle.resizeWidth(15);
rectangle.resizeHeight(25);
@Override
public void resizeWidth(int width) {
this.width = width;
}
@Override
public void resizeHeight(int height) {
this.height = height;
}
}
8.Develop a JAVA program to create an outer class with a function display. Create another class
inside the outer class named inner with a function called display and call the two functions in the
main class.
class Outer {
void display() {
System.out.println("Outer class display()");
}
class Inner {
void display() {
System.out.println("Inner class display()");
}
}
}
9.Develop a JAVA program to raise a custom exception (user defined exception) for
DivisionByZero using try, catch, throw and finally.
if (denominator == 0) {
// If denominator is zero, throw the custom exception
throw new DivisionByZeroException("Division by zero is not allowed");
}
} catch (DivisionByZeroException e) {
// Catch the custom exception and handle it
System.out.println("Custom Exception Caught: " + e.getMessage());
} finally {
// Finally block executes whether an exception occurs or not
System.out.println("Finally block executed");
}
}
}
10.Develop a JAVA program to create a package named mypack and import & implement it in a
suitable class.
package mypack;
/////////////////////////////
import mypack.MyClass;
11.Write a program to illustrate creation of threads using runnable class. (start method start each of the
newly created thread. Inside the run method there is sleep() for suspend the thread for 500 milliseconds).
12.Develop a program to create a class MyThread in this class a constructor, call the base class
constructor, using super and start the thread. The run method of the class starts after this. It can
be observed that both main thread and created child thread are executed concurrently.