Final OOP Manual-2
Final OOP Manual-2
Vision:
PMC TECH strives to achieve excellence in technical Education through innovative teaching, learning
and applied Multidisciplinary research with professional and ethical practices.
Mission:
PMC TECH will Endeavour
To become the state of art teaching and learningcenter for Engineering and Technology,
Research and Management Studies
To have world class infrastructure for providing quality education and research towards
creativity,self discipline and ethical values
To associate with industry, R&D and business organizations and to have connectivity with the
society
To create knowledge, based professionals to enrich their quality of life by empowering self and
family.
Mission:
M1: To imbibe high quality knowledge, skills and practices of computer science engineering through
quality infrastructure and resources.
M2: To endow the students to solve simple solutions to complex engineering problems through
software.
M3: To provide strong software development skills for lifelong learning, to meet the challenges of
industry and society.
PROGRAM OUTCOMES:
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PSO2: Design, analyze and develop systems in the areas of networking, software engineering,
artificial intelligence, machine learning, Internet of Things and Cloud computing.
PSO3: Apply programming skill, Agile and Extreme Programming to solve the industrial and societal
problems.
CS3381 OBJECT ORIENTED PROGRAMMING LABORATORY (2021-REGULATION)
COURSE OBJECTIVES:
To build software development skills using java programming for real-world applications.
To understand and apply the concepts of classes, packages, interfaces, inheritance, exception handling
and file processing.
To develop applications using generic programming and event handling
LIST OF EXPERIMENTS:
1. Solve problems by using sequential search, binary search, and quadratic sorting algorithms
(selection, insertion)
2. Develop stack and queue data structures using classes and objects.
3. Develop a java application with an Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate
Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the
inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for
staff club funds. Generate pay slips for the employees with their gross and net salary.
4. Write a Java Program to create an abstract class named Shape that contains two integers and an
empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method printArea( ) that prints the area of the given shape
5. Solve the above problem using an interface.
6. Implement exception handling and creation of user defined exceptions.
7. Write a java program that implements a multi-threaded application that has three threads. First
thread generates a random integer every 1 second and if the value is even, the second thread
computes the square of the number and prints. If the value is odd, the third thread will print the
value of the cube of the number.
8. Write a program to perform file operations.
9. Develop applications to demonstrate the features of generics classes.
10. Develop applications using JavaFX controls, layouts and menus.
11. Develop a mini project for any application using Java concepts.
TOTAL: 45 PERIODS
COURSE OUTCOMES:
On completion of this course, the students will be able to
CO1 : Design and develop java programs using object oriented programming concepts
CO2 : Develop simple applications using object oriented concepts such as package, exceptions
CO3: Implement multithreading, and generics concepts
CO4 : Create GUIs and event driven programming applications for real world problems
CO5: Implement and deploy web applications using Java
ATTAINMENT OF PROGRAM OUTCOMES & PROGRAM SPECIFIC OUTCOMES
CO Level Outcome
CO & PO MAPPING
P P P P P P P P P PO PO PO PS PS PS
CO
O1 O2 O3 O4 O5 O6 O7 O8 O9 10 11 12 O1 O2 O3
C20
3 3 3 2 1 - - 1 2 1 - 2 3 3 3
7.1
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.2
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.3
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.4
C20
3 3 3 3 3 - - 1 2 1 - 2 3 3 3
7.5
C20
3 3 3 2.8 2.6 - - 1 2 1 - 2 3 3 3
7
CS3381-OBJECT ORIENTED
PROGRAMMINGLABORATORY
CONTENTS
1. Implementationissuesrelatedtoobject-orientedtechniques
2. Understandingstructsandapplythemin C++programs.
EX. NO:1
GENERATIONDATE:
PROGRAM:
import java.util.Scanner;
public class Lab_001 {
public static void main(String[] args)
{
intc,n,search,array[];
Scanner S=new Scanner(System.in);
System.out.println("enter the number of elements");
n=S.nextInt();
array=new int[n];
System.out.println("enter those elements:");
for(c=0;c<n;c++)
array[c]=S.nextInt();
System.out.println("enter value to find:");
search=S.nextInt();
for(c=0;c<n;c++)
{
if(array[c]==search){
System.out.println(search+"present at location"+(c+1));
break;
}
}
if(c==n)
System.out.println(search+"is not present in array:");
}
}
OUTPUT :
PROGRAM :
import java.util.*;
public class Lab_002 {
OUTPUT :
PROGRAM:
import java.util.Arrays;
public class SelectionSort {
}
}
OUTPUT :
PROGRAM :
OUTPUT :
EX NO:2
DATE :
Develop stack and queue data structures using classes and objects
PROGRAM:
import java.util.*;
public class StackDemo { static void showpush(Stack st, int a) { st.push(new Integer(a));
System.out.println("push(" + a + ")");
System.out.println("stack: " + st);
}
static void showpop(Stack st) { System.out.print("pop -> ");
Integer a = (Integer) st.pop();
System.out.println(a);
System.out.println("stack: " + st);
}
public static void main(String args[]) { Stack st = new Stack();
System.out.println("stack: " + st);
showpush(st, 42);
showpush(st, 66);
showpush(st, 99);
showpop(st);
showpop(st);
showpop(st);
try { showpop(st);
}
catch (EmptyStackException e)
{ System.out.println("empty stack");
}}}
OUTPUT:
PROGRAM:
OUTPUT:
EX NO: 3
DATE :
Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate
Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the
inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for
staff club fund. Generate pay slips for the employees with their gross and net salary
PROGRAM :
import java.util.Scanner;
class Employee{
String Emp_name;
intEmp_id;
String Address;
String Mail_id;
intMobile_no;
void display(){
System.out.println(Emp_name);
System.out.println(Mail_id);
int BP;
HRA=(int) (0.10*BP);
PF=(int) (0.12*BP); */
void display(){
System.out.println(BP);
System.out.println("DA"+0.97*BP);
System.out.println("HRA"+0.10*BP);
System.out.println("PF"+0.12*BP);
void display(){
System.out.println(BP);
System.out.println("DA"+0.97*BP);
System.out.println("HRA"+0.10*BP);
System.out.println("PF"+0.12*BP);
}}
int BP;
void display(){
System.out.println(BP);
System.out.println("DA"+0.97*BP);
System.out.println("HRA"+0.10*BP);
System.out.println("PF"+0.12*BP);
int BP;
void display(){
System.out.println(BP);
System.out.println("DA"+0.97*BP);
System.out.println("HRA"+0.10*BP);
System.out.println("PF"+0.12*BP);
System.out.println("\n 1.Programmer\n2.Assistant_Professor\n3.Associate_Professor\
n4.Professor");
intch=input.nextInt();
switch (ch) {
case 1:
e1.Emp_name="ABC";
e1.Address="y-city";
e1.Mail_id="[email protected]";
e1.Emp_id=567;
e1.Mobile_no=2345678;
p1.BP=15000;
p1.display();
e1.display();
break;
case 2:
e2.Emp_name="DEF";
e2.Address="A-city";
e2.Mail_id="[email protected]";
e2.Emp_id=123;
e2.Mobile_no=987321;
p2.BP=30000;
p2.display();
e2.display();
break;
case 3:
e3.Emp_name="GHF";
e3.Address="B-city";
e3.Mail_id="[email protected]";
e3.Emp_id=456;
e3.Mobile_no=98710;
p3.BP=30000;
p3.display();
e3.display();
break;
case 4:
e4.Emp_name="KANNAN";
e4.Address="TRICHY";
e4.Mail_id="[email protected]";
e4.Emp_id=789;
e4.Mobile_no=9810;
p4.BP=30000;
p4.display();
e4.display();
break;
case 5:
//exit(1);
default:
OUTPUT:
EX NO: 4
DATE :
Write a Java Program to create an abstract class named Shape that contains two integers and an
empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method printArea( ) that prints the area of the given shape.
PROGRAM:
import java.util.Scanner;
abstract class Shape {
int a = 10, b = 2;
Rectangle(int a, int b) {
super(a, b);
}
void Printarea() {
System.out.println("area of rectangle is " + (a * b));
}
Triangle(int a, int b) {
super(a, b);
}
void Printarea(){
System.out.println("area of triangle is " + (0.5 * a * b));
}
Circle(int a, int b) {
super(a, b);
}
void Printarea() {
System.out.println("area of circle is " + (3.14 * a * a));
}
public class Z {
String input;
int width, height;
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("which shape? circle/rectangle/triangle (write any other thing for quitting): ");
input = scanner.nextLine();
if(!"circle".equalsIgnoreCase(input) && !"rectangle".equalsIgnoreCase(input)
&& !"triangle".equalsIgnoreCase(input) ){
System.exit(0);
}
System.out.println("height: ");
height =scanner.nextInt();
System.out.println("width: ");
width = scanner.nextInt();
if("circle".equalsIgnoreCase(input)){
shape=new Circle(width, height);
}
else if("rectangle".equalsIgnoreCase(input)){
shape=new Rectangle(width, height);
}
else{ // == triangle
shape=new Triangle(width, height);
}
shape.Printarea();
}
}
}
OUTPUT:
EX NO:5
DATE :
PROGRAM:
OUTPUT:
EX NO:6
DATE :
PROGRAM:
import java.util.Scanner;
public class Predefinedexceptions {
PROGRAM:
import java.util.*;
class NegativeAmtException extends Exception
{
String msg;
NegativeAmtException(String msg)
{
this.msg=msg;
}
public String toString()
{
return msg;
}
}
public class Userdefined {
}
}
OUTPUT :
EX NO:7
DATE :
Write a java program that implements a multi-threaded application that has three threads. First
thread generates a random integer every 1 second and if the value is even, the second thread
computes the square of the number and prints. If the value is odd, the third thread will print the
value of the cube of the number.
PROGRAM :
import java.util.Random;
class Square extends Thread
{
int x;
Square(int n)
{
x = n;
}
public void run()
{
intsqr = x * x;
System.out.println("Square of " + x + " = " + sqr );
}
}
class Cube extends Thread
{
int x;
Cube(int n)
{x = n;
}
public void run()
{
int cub = x * x * x;
System.out.println("Cube of " + x + " = " + cub );
}
}
class Number extends Thread
{
public void run()
{
Random random = new Random();
for(inti =0; i<2; i++)
{
intrandomInteger = random.nextInt(100);
System.out.println("Random Integer generated : " + randomInteger);
Square s = new Square(randomInteger);
s.start();
Cube c = new Cube(randomInteger);
c.start();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
System.out.println(ex);
}
}
}
}
public class MultiThread {
public static void main(String args[])
{
Number n = new Number();
n.start();
}
}
OUTPUT:
EX NO:8
DATE :
FILE OPERATIONS:
1.creating a File
2.Get File Information
3.Write to a File
4.Read from a File
5.Delete a File
PROGRAM:
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Handling {
OUTPUT:
EX NO:9
DATE :
PROGRAM:
// variable of T type
private T data;
OUTPUT :
EX NO:10
DATE :
PROGRAM :
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
@Override
public void start(Stage primaryStage) {
Text text1 = new Text("Email");
//Creating Buttons
Button button1 = new Button("Submit");
Button button2 = new Button("Clear");
OUTPUT :
EX NO:11
DATE :
11.A)password generator
PROGRAM :
import java.util.*;
public class PassGen {
public static void main(String[] args)
{
// Length of your password as I have choose
// here to be 8
int length = 10;
System.out.println(geek_Password(length));
}
}
return password;
}
}
OUTPUT :
PROGRAM :
import java.util.Scanner;
public class Income {
OUTPUT :
PROGRAM:
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Snap extends javax.swing.JFrame {
public Snap() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("qr generator");
jLabel2.setText("select link");
link.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
linkActionPerformed(evt);
}
});
jButton1.setText("submit");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
pack();
}// </editor-fold>
MatrixToImageWriter.writeToFile(matrix, filepath.substring(filepath.lastIndexOf('.')+1),new
File(filepath));
System.out.println("Qr code has been generated at the location "+filepath);
java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(qr.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>