Oops Manual
Oops Manual
TECHNOLOGY
UDAYA NAGAR, VELLAMODI
KANYAKUMARI DISTRICT
Reg. No:
Name :
Semester :
Department :
Subject Name :
Subject Code :
SUN COLLEGE OF ENGINEERING AND
TECHNOLOGY
UDAYA NAGAR, VELLAMODI
Kanyakumari District
Bonafide Certificate
AIM:
ALGORITHM:
PROGRAM:
import java.util.Scanner;
class Linear
{
public static void main(String args[])
{
int i,len, key, array[];
Scanner input = new Scanner(System.in);
System.out.println("Enter Array length:");
len = input.nextInt();
array = new int[len];
System.out.println("Enter " + len + " elements");
for (i = 0; i < len; i++)
{
array[i] = input.nextInt();
}
System.out.println("Enter the search key value:");
key = input.nextInt();
for (i = 0; i < len; i++)
{
if (array[i]== key)
{
System.out.println(key+" is present at location "+(i+1));
break;
}
}
if (i == len)
System.out.println(key + " doesn't exist in array.");
}
}
OUTPUT:
RESULT:
Thus the Implementation of sequential search program is executed successfully.
ExNo: 1(b) BINARY SEARCH
Date:
AIM:
ALGORITHM:
PROGRAM:
import java.util.Scanner;
public class Binary {
else
high = mid - 1;
}
return -1;
}
OUTPUT:
RESULT:
Thus the Implementation of Binary search program is executed successfully.
ExNo: 1(c) SELECTION SORTING
Date:
AIM:
To Develop Java program for Selecting Sorting Using Array.
ALGORITHM:
PROGRAM:
import java.util.Scanner;
public class SSort
{
public static void Sort(int a[])
{
int n=a.length,i,j,p,temp;
for (i = 0; i < n - 1; i++)
{
p = i;
for (j=i+1; j < n; j++)
{
if (a[p]>a[j])
p=j;
}
temp=a[p];
a[p]=a[i];
a[i]=temp;
}
}
public static void printarray(int a[])
{
for(int i=0; i < a.length; i++)
{
System.out.print(a[i]+" ");
}
}
public static void main(String[] args)
{
int n, res,i;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter "+n+" elements ");
for( i=0; i < n; i++)
{
a[i] = s.nextInt();
}
OUTPUT:
AIM:
To develop Java program for Insertion Sorting using Array.
ALGORITHM:
PROGRAM:
import java.util.Scanner;
public class ISort
{
public static void Sort(int a[])
{
int n=a.length,i,j,p,temp;
for (i = 1;i < n; i++)
{
for (j=i-1; j >=0 && a[j+1]<a[j]; j--)
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
public static void printarray(int a[])
{
for(int i=0; i < a.length; i++)
{
System.out.print(a[i]+" ");
}
}
public static void main(String[] args)
{
int n, res,i;
Scanner s = new Scanner(System.in);
System.out.print("Enter number of elements in the array:");
n = s.nextInt();
int a[] = new int[n];
System.out.println("Enter "+n+" elements ");
for( i=0; i < n; i++)
{
a[i] = s.nextInt();
}
OUTPUT:
RESULT:
Thus the Implementation of Insertion Sort program is executed successfully.
ExNo: 2(a) STACK IMPLENETATION USING CLASS AND OBJECT
Date:
AIM:
To develop Java program for Stack Implementation using Class and Object.
ALGORITHM:
1. Create stack and Store elements in stack for push pop operation
2. Push the elements to the top of stack, before push element in stack should stack is not full
3. Pop the elements from the stack should not be empty.
4. After the push and pop operation print the stack elements
5. Stop the process.
PROGRAM:
class stack {
private int arr[];
private int top;
private int capacity;
stack(int size) {
arr = new int[size];
capacity = size;
top = -1;
}
public void push(int x) {
if (isFull()) {
System.out.println("Stack OverFlow");
System.exit(1);
}
System.out.println("Inserting " + x);
arr[++top] = x;
}
public int pop() {
if (isEmpty()) {
System.out.println("STACK EMPTY");
System.exit(1);
}
return arr[top--];
}
public int getSize() {
return top + 1;
}
public Boolean isEmpty() {
return top == -1;
}
public Boolean isFull() {
return top == capacity - 1;
}
public void printStack() {
for (int i = 0; i <= top; i++) {
System.out.print(arr[i] + ", ");
}
}
public static void main(String[] args) {
stack stack = new stack(5);
stack.push(1);
stack.push(2);
stack.push(3);
System.out.print("Stack: ");
stack.printStack();
stack.pop();
System.out.println("\nAfter popping out");
stack.printStack();
}
}
OUTPUT:
Inserting 1
Inserting 2
Inserting 3
Stack: 1, 2, 3,
After popping out
1, 2,
RESULT:
Thus the Implementation of Stack push, pop operation program is executed successfully.
ExNo: 2(b) QUEUE IMPLENETATION USING CLASS AND OBJECT
Date:
AIM:
To develop Java program for Queue Implementation using class and object.
ALGORITHM:
1. Enqueue: Adds an item from the back of the queue.
2. Dequeue: Removes an item from the front of the queue.
3. Front/Peek: Returns the value of the item in front of the queue without dequeuing (removing)
the item.
4. IsEmpty: Checks if the queue is empty.
5. IsFull: Checks if the queue is full.
6. Display: Prints all the items in the queue.
PROGRAM:
Rear index-> 4
1 Deleted
Front index-> 1
Items ->
2 3 4 5
Rear index-> 4
RESULT:
Thus the Implementation of Queue enqueue, dequeue operation program is
executed successfully.
ExNo: 3 GENERATING EMPLOYEE PAYROLL DETAILS
Date:
AIM:
To develop a java application for generating pay slips of employees with their Gross
And Net salary.
ALGORITHM:
PROGRAM:
package employee;
public class Employee
{
private String name;
private String id;
private String address;
private String mailId;
private String mobileNo;
public Employee(String name, String id, String address, String mailId, String mobileNo)
{
this.name= name;
this.id= id;
this.address= address;
this.mailId= mailId;
this.mobileNo= mobileNo;
}
public void display()
{
System.out.println("Emp_Name : "+ name + "\t" + "Emp_id : "+ id);
System.out.println("Address : " + address);
System.out.println("Mail_id : "+ mailId + "\t" + "Mobile_no : " + mobileNo);
}
public void paySlip()
{
}
}
package employee;
public class Programmer extends Employee
{
private float bPay;
private String des;
public Programmer(String name, String id, String address, String mailId, String mobileNo,
float bPay, String des)
{
super(name, id, address, mailId, mobileNo);
this.bPay= bPay;
this.des= des;
}
public void paySlip()
{
float da=bPay*97/100;
float hra=bPay*10/100;
double grossSalary=bPay + da + hra;
float pf=bPay*12/100;
double scf=bPay*0.1/100;
double netSalary=grossSalary - pf - scf;
System.out.println("------------ Employees Pay Slips ------------- ");
super.display();
System.out.println("Designation: "+des);
System.out.println("Basic_Pay: "+bPay);
System.out.println("Gross Salary : "+ grossSalary + "\t" + "Net Salary : " + netSalary);
System.out.println("------------ End of the Statements ----------- ");
}
}
//For Packages, Folder Name should be employee
// File Name should be AssistantProfessor.java
package employee;
public class AssistantProfessor extends Employee
{
private float bPay;
private String des;
public AssistantProfessor(String name, String id, String address, String mailId, String
mobileNo, float bPay, String des)
{
super(name, id, address, mailId, mobileNo);
this.bPay= bPay;
this.des= des;
}
public void paySlip()
{
float da=bPay*97/100;
float hra=bPay*10/100;
double grossSalary=bPay + da + hra;
float pf=bPay*12/100;
double scf=bPay*0.1/100;
double netSalary=grossSalary - pf - scf;
System.out.println("------------ Employees Pay Slips ------------- ");
super.display();
System.out.println("Designation: "+des);
System.out.println("Basic_Pay: "+bPay);
System.out.println("Gross Salary : "+ grossSalary + "\t" + "Net Salary : " + netSalary);
System.out.println("------------ End of the Statements ----------- ");
}
}
package employee;
public class AssociateProfessor extends Employee
{
private float bPay;
private String des;
public AssociateProfessor(String name, String id, String address, String mailId, String
mobileNo, float bPay, String des)
{
super(name, id, address, mailId, mobileNo);
this.bPay= bPay;
this.des= des;
}
public void paySlip()
{
float da=bPay*97/100;
float hra=bPay*10/100;
double grossSalary=bPay + da + hra;
float pf=bPay*12/100;
double scf=bPay*0.1/100;
double netSalary=grossSalary - pf - scf;
System.out.println("------------ Employees Pay Slips ------------- ");
super.display();
System.out.println("Designation: "+des);
System.out.println("Basic_Pay: "+bPay);
System.out.println("Gross Salary : "+ grossSalary + "\t" + "Net Salary : " + netSalary);
System.out.println("------------ End of the Statements ----------- ");
}
}
package employee;
public class Professor extends Employee
{
private float bPay;
private String des;
public Professor(String name, String id, String address, String mailId, String mobileNo, float
bPay, String des)
{
super(name, id, address, mailId, mobileNo);
this.bPay= bPay;
this.des= des;
}
public void paySlip()
{
float da=bPay*97/100;
float hra=bPay*10/100;
double grossSalary=bPay + da + hra;
float pf=bPay*12/100;
double scf=bPay*0.1/100;
double netSalary=grossSalary - pf - scf;
System.out.println("------------ Employees Pay Slips ------------- ");
super.display();
System.out.println("Designation: "+des);
System.out.println("Basic_Pay: "+bPay);
System.out.println("Gross Salary : "+ grossSalary + "\t" + "Net Salary : " + netSalary);
System.out.println("------------ End of the Statements ----------- ");
}
}
//File Name should be Emp.java separate this file from above folder
import employee.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Emp
{
Employee e;
ArrayList<Employee> obj= new ArrayList<>();
Scanner get= new Scanner(System.in);
public void addEmployee()
{
System.out.println("Enter the Emp_Name:");
String name = get.next();
System.out.println("Enter the Emp_id:");
String id = get.next();
System.out.println("Enter the Address:");
String address = get.next();
System.out.println("Enter the Mail_id:");
String mailId = get.next();
System.out.println("Enter the Mobile_no:");
String mobileNo = get.next();
System.out.println("Enter the Designation:");
String des = get.next();
System.out.println("Enter the Basic_Pay:");
float bPay = get.nextFloat();
if(des.equalsIgnoreCase("Programmer"))
{
e= new Programmer(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
}
else if(des.equalsIgnoreCase("AssistantProfessor"))
{
e= new AssistantProfessor(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
}
else if(des.equalsIgnoreCase("AssociateProfessor"))
{
e= new AssociateProfessor(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
}
else if(des.equalsIgnoreCase("Professor"))
{
e= new Professor(name, id, address, mailId, mobileNo, bPay, des);
obj.add(e);
}
}
public void displayEmployee()
{
for(Employee e:obj)
{
e.paySlip();
}
}
public static void main(String args[]) throws IOException
{
Emp x= new Emp();
String check;
do
{
x.addEmployee();
System.out.println("Do you wnat continue press 'y'");
check=x.get.next();
}
while(check.equalsIgnoreCase("y"));
x.displayEmployee();
}
}
NOTE:
OUTPUT:
D:\>javac Emp.java
D:\>java Emp
Enter the Emp_Name:
Suresh
Enter the Emp_id:
E708
Enter the Address:
cuddalore
Enter the Mail_id:
suresh708@tgarments.org
Enter the Mobile_no:
7894561230
Enter the Designation:
Programmer
Enter the Basic_Pay:
7500
Do you wnat continue press 'y'
y
Enter the Emp_Name:
Rakesh
Enter the Emp_id:
E705
Enter the Address:
pondy
Enter the Mail_id:
rakesh@gmail.com
Enter the Mobile_no:
4567891230
Enter the Designation:
Professor
Enter the Basic_Pay:
15000
Do you wnat continue press 'y'
y
Enter the Emp_Name:
kumar
Enter the Emp_id:
E405
Enter the Address:
madurai
Enter the Mail_id:
kumarat@ymail.com
Enter the Mobile_no:
1237894560
Enter the Designation:
AssistantProfessor
Enter the Basic_Pay:
18000
Do you wnat continue press 'y'
y
Enter the Emp_Name:
Naresh
Enter the Emp_id:
E102
Enter the Address:
villupuram
Enter the Mail_id:
nar12@rediffmail.com
Enter the Mobile_no:
9873214560
Enter the Designation:
AssociateProfessor
Enter the Basic_Pay:
20000
Do you wnat continue press 'y'
n
------------ Employees Pay Slips ------------
Emp_Name : Suresh Emp_id : E708
Address : cuddalore
Mail_id : suresh708@tgarments.org Mobile_no : 7894561230
Designation: Programmer
Basic_Pay: 7500.0
Gross Salary : 15525.0 Net Salary : 14617.5
------------ End of the Statements -----------
------------ Employees Pay Slips ------------
Emp_Name : Rakesh Emp_id : E705
Address : pondy
Mail_id : rakesh@gmail.com Mobile_no : 4567891230
Designation: Professor
Basic_Pay: 15000.0
Gross Salary : 31050.0 Net Salary : 29235.0
------------ End of the Statements -----------
------------ Employees Pay Slips ------------
Emp_Name : kumar Emp_id : E405
Address : madurai
Mail_id : kumarat@ymail.com Mobile_no : 1237894560
Designation: AssistantProfessor
Basic_Pay: 18000.0
Gross Salary : 37260.0 Net Salary : 35082.0
------------ End of the Statements -----------
------------ Employees Pay Slips ------------
Emp_Name : Naresh Emp_id : E102
Address : villupuram
Mail_id : nar12@rediffmail.com Mobile_no : 9873214560
Designation: AssociateProfessor
Basic_Pay: 20000.0
Gross Salary : 41400.0 Net Salary : 38980.0
------------ End of the Statements -----------
RESULT:
Thus the application for generating pay slips of employees with their gross and net salary has been
successfully executed.
ExNo: 4 FINDING THE AREA OF DIFFERENT SHAPE USING ABSTRACT CLASS
Date:
AIM:
To write a java program to find the area of different shapes by using abstract class.
ALGORITHM:
PROGRAM:
import java.io.*;
import java.util.*;
OUTPUT:
RESULT:
Thus the Implementation for finding the area of different shapes using abstract classhas been successfully
executed.
ExNo: 5 CIRCLE, RECTANGLE, TRIANGLE AREA CALCULATION
Date: USING INTERFACE
AIM:
To develop Java program Shape Area Calculation Using Interface.
ALGORITHM:
1. Import the java packages.
2. Create an Interface named Area that contains two integers and an method named Compute().
3. Create a class Rectangle that implements Area. then compute the area and prints the area
of the Rectangle.
4. Create a class Triangle that implements the class Area. then compute the area and prints
the area of the Triangle.
5. Create a class Circle that implenets the class Area. then compute the area and prints the
area of the Circle.
6. Create object for a class in memory and assign it to the reference variable, then the method
is invoked.
PROGRAM:
}
}
OUTPUT:
RESULT:
Thus the Implementation of different shape area calculated using Interface program is executed
successfully.
ExNo: 6 USER DEFINED EXCEPTION
Date:
AIM:
ALGORITHM:
PROGRAM:
import java.io.*;
import java.util.*;
class UserException
{
static void compute(int a) throws MyException
{
System.out.println ("Called Compute(" + a + ")");
if(a>10)
throw new MyException(a);
System.out.println ("Normal Exit");
}
public static void main(String args[])
{
try
{
compute(1);
compute(20);
}
catch(MyException e)
{
System.out.println("Caught " + e);
}
}
}
NOTE:
To Compile:
javac UserException.java
To Run:
java UserException
OUTPUT:
RESULT:
Thus the Implementation for user defined exception handling has been successfully executed.
ExNo: 7 MULTI THREADED APPLICATION
Date:
AIM:
ALGORITHM:
PROGRAM:
import java.util.*;
NOTE:
To Compile:
javac Multithread.java
To Run:
java Multithread
OUTPUT:
RESULT:
Thus the Implementation for application for multithreading has been successfully executed.
ExNo: 8 FILE OPERATION
Date:
AIM:
To write a java program to implement file information such as reads a file name from
the user, displays information about whether the file exists, whether the file is readable, or
writable, the type of file and the length of the file in bytes.
ALGORITHM:
PROGRAM:
import java.io.*;
import java. util.*;
public class FileInfo
{
public static void main(String[] args) throws IOException
{
Scanner in=new Scanner(System.in);
if(f.exists())
{
result = f.canRead() ? "readable." : "not readable.";
System.out.println("\nThe file is " + result);
NOTE:
To Compile:
javac FileInfo.java
To Run:
java FileInfo
OUTPUT:
RESULT:
Thus the Implementation for getting file information has been successfully executed.
ExNo: 9 GENERIC CLASSES
Date:
AIM:
To write a java program to find the maximum value from the given type of elements
using a generic function.
ALGORITHM:
PROGRAM:
import java.util.*;
class MyGeneric {
public static <T extends Comparable<T>> T max(T... elements)
{
T max = elements[0];
for (T element : elements) {
if (element.compareTo(max) > 0)
{
max = element;
}
}
return max;
}
NOTE:
To Compile:
javac MyGeneric.java
To Run:
java MyGeneric
OUTPUT:
RESULT:
Thus the Implementation for finding the maximum value from the given type of
elements using a generic function has been successfully executed.
ExNo: 10 JAVAFX CONTROLS, LAYOUTS AND MENUS
Date:
AIM:
To develop Java program for creating controls, layouts and menus using JavaFX.
ALGORITHM:
1. Open new JavaFX New Application and save file name as JavaFXMenuSample
2. Import Supporting packages into program and extends javafx application object Application.
4. Create menu and cerate menu items add the menu items to menu bar.
PROGRAM:
package javafxapplicationmenu;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
@Override
public void start(Stage stage) {
// Create MenuBar
MenuBar menuBar = new MenuBar();
// Create menus
Menu fileMenu = new Menu("File");
Menu editMenu = new Menu("Edit");
Menu helpMenu = new Menu("Help");
// Create MenuItems
MenuItem newItem = new MenuItem("New");
MenuItem openFileItem = new MenuItem("Open File");
MenuItem exitItem = new MenuItem("Exit");
OUTPUT:
RESULT:
Thus the Implementation for JavaFX control, layout, menu program is executed successfully.
ExNo: 11 MINI PROJECT - OPAC SYSTEM
Date:
AIM:
To develop a mini project OPAC system for library using Java concepts.
ALGORITHM:
PROGRAM:
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Data extends JFrame implements ActionListener
{
JTextField id;
JTextField name;
JButton next;
JButton addnew;
JPanel p;
static ResultSet res;
static Connection conn;
static Statement stat;
public Data()
{
super("My Application");
Container c = getContentPane();
c.setLayout(new GridLayout(5,1));
id = new JTextField(20);
name = new JTextField(20);
next = new JButton("Next BOOK");
p = new JPanel();
p.add(next);
next.addActionListener(this);
pack();
setVisible(true);
addWindowListener(new WIN());
}
NOTE:
Create a new Database
1. Create a new Database file in MS ACCESS (our backend) named “books.mdb”.
2. Then create a table named “stu” in it.
3. The table stu contains the following fields and data types
i. ISBN - Text
ii. BookName - Text
4. Enter various records as you wish.
5. Save the database file.
Next step is to add our “books.mdb” to the System DSN. To do that follows the procedure
given below,
i. Go to Start-> Control Panel -> Administrative tools.
ii. In that double click “Data Sources (ODBC)”.
iii. ODBC Data Source Administrator dialog appears.
iv. In that select “System DSN” tab and click the Add Button.
v. Select “Microsoft Access Driver(*.mdb)” and click Finish.
vi. ODBC Microsoft Access Setup appears. In the “Data Source name” type “stu”.
vii. Click on the “Select” button and choose your database file. Then click ok.
To Compile:
javac Data.java
To Run:
java Data
RESULT:
Thus the program to develop the simple OPAC for the libraries is executed successfully.