0% found this document useful (0 votes)
18 views16 pages

Oops Manual 7,8,9

Uploaded by

saishivanie13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views16 pages

Oops Manual 7,8,9

Uploaded by

saishivanie13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

EXPT NO:7 DEVELOPMENT OF QUEUE DATA STRUCTURE

AIM: To develop queue data structure.

OBJECTIVE: To learn and perform various operations of queue.

SOFTWARE REQUIRED: Netbeans IDE

ALGORITHM:

STEP 1 : Start

STEP 2: Declare an array q and initialize front and rear as -1.

STEP 3: Do the following steps till choice value 4 is encountered.

STEP 3.1: Display the operations that can be performed and read choice as ch.

STEP 3.2: Using switch case, check each case and perform the operations.

STEP 3.2.1: If ch is 1, read the number of elements to insert , read the


elements and insert the elements into the queue by calling enqueue() method.

STEP 3.2.2: If ch is 2, call the dequeue() method.

STEP 3.2.3: If ch is 3, call the display() method.

STEP 3.2.4: If ch is 4, display Thank you and Exit.

STEP 3.2.5: If all the cases are false then display Wrong input.

STEP 4: Stop

enqueue() method:

STEP 1: If the value of rear is equl to maximum size then display Overflow.

STEP 2: Else check if the values of front and rear are equal to -1. If true then assign 0
to front and rear.

STEP 3: Otherwise increment rear value.

STEP 4: Assign the element to be inserted.

dequeue() method:

STEP 1: Check if front=-1or rear<front, then display Underflow.

STEP 2: Else, assign q[front] to val.


STEP 2.1: Check if front>=rear, then assign -1 to front and rear. Otherwise
increment front value.

STEP 2.2: Display val as element deleted.

STEP 3: Return the value of val.

display() method:

STEP 1: Check if front=-1 or front>rear, then display Underflow(empty queue).

STEP 2: Otherwise, display the queue.

PROGRAM:

import java.util.Scanner;
class Queuefn
{
public int q[],max,front,rear,val;
Queuefn()
{
max=20;
q=new int[max];
front=-1;
rear=-1;
}
public void enqueue(int num)
{
if(rear==max)
{
System.out.println("\n Overflow");
}
else if(front==-1 && rear==-1)
{
front=0;
rear=0;
}
else
{
rear++;
}
q[rear]=num;
}
public int dequeue()
{
if(front==-1 || front>rear)
{
System.out.println("\n Underflow");
}
else
{
val=q[front];
if(front>=rear)
{
front=-1;
rear=-1;
}
else
{
front++;
}
System.out.println("The element deleted :"+val);
}
return val;
}
public void display()
{
if(front==-1 || front>rear)
{
System.out.println("\n Queue is empty");
System.exit(1);
}
for(int i=front;i<=rear;i++)
{
System.out.print(q[i]+" ");
}
}
}
class Queue
{

private static int ch;


public static void main(String args[])
{
Queuefn q1=new Queuefn();
Scanner sc=new Scanner(System.in);
System.out.println("Queue operations");
do
{
System.out.println("\nMENU\n1.Enqueue\n2.Dequeue\n3.Display\n4.Exit");
System.out.print("Enter the choice :");
ch=sc.nextInt();
switch(ch)
{
case 1:
System.out.print("Enter the no.of elements:");
int n=sc.nextInt();
System.out.println("Enter the elements:");
for(int i=0;i<n;i++)
{
q1.q[i]=sc.nextInt();
q1.enqueue(q1.q[i]);
}
break;
case 2:
q1.dequeue();
break;
case 3:
q1.display();
break;
case 4:
System.out.println("Thank you");
break;
default:
System.out.println("Wrong input");
}
}while(ch!=4);
}
}
OUTPUT:

RESULT:

The program to implement queue data structure was successfully executed.


EXPT NO:8 GENERATION OF EMPLOYEE PAY SLIP

AIM: To generate employee pay slip.

OBJECTIVE: To understand the concept of inheritance.

SOFTWARE REQUIRED: Netbeans IDE

ALGORITHM:

STEP 1 : Start

STEP 2: Declare class Employee with data members


emp_id,emp_name,address,mail_id,mob_no,bp,hra,da,pf,cf,gp,np and methods
getdata(),display(),calculate() and payslip.

STEP 3: Derive 4 subclass Programmer,Assistant_Professor,Associate_Professor and


Professor from Employee class and define a method get_bp() in each of the derived
class.

(Main class)

STEP 4: Create a main class and display the designation for which payslip has to be
calculated and read choice.

STEP 5: Repeat the following steps till ch!=5.

STEP 6: Using switch case check all the cases.

STEP 6.1: If ch is 1,call the methods from Programmer class.

STEP 6.2: If ch is 2,call the methods from Assistant_Programmer class.

STEP 6.3: If ch is 3,call the methods from Associate_Professor class.

STEP 6.4: If ch is 4,call the methods from Professor class.

STEP 6.5: If all the cases are false then display Wrong Input and Exit.

STEP 7: Stop
getdata() method:

STEP 1: Read the data for emp_id,emp_name,mail_id,address,mob_no.

display() method:

STEP 1: Display emp_id,emp_name,mail_id,address,mob_no.

get_bp() method:

STEP 1: Read the value for basic pay as bp.

calculate() method:

STEP 1: Compute da as bp*0.97, hra as 0.1*bp andcf as 0.001*bp.

STEP 2: Calculate gp as sum of bp,da and hra.

STEP 3: Compute np as gf-pf-cf.

payslip() method:

STEP 1: Display the computed values of bp,da,hra,pf,cf,gp and np.

PROGRAM:

import java.util.Scanner;
class Employee
{
String emp_id,emp_name,address,mail_id;
long mob_no;
double bp,hra,da,pf,cf,gp,np;
Scanner sc=new Scanner(System.in);
void getdata()
{
System.out.print("\nEnter Employee id:");
emp_id=sc.nextLine();
System.out.print("Enter Employee name:");
emp_name=sc.nextLine();
System.out.print("Enter Employee's Email id:");
mail_id=sc.nextLine();
System.out.print("Enter Employee Address:");
address=sc.nextLine();
System.out.print("Enter Employee's Phone number:");
mob_no=sc.nextInt();
}

void display()
{
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("DISPLAYING DETAILS");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Name: "+emp_name);
System.out.println("ID: "+emp_id);
System.out.println("E-Mail ID: "+mail_id);
System.out.println("Mobile: "+mob_no);
System.out.println("Address: "+address);
}
void calcualte()
{
da=(bp*0.97);
hra=(0.10*bp);
pf=(0.12*bp);
cf=(0.1*bp);
gp=(bp+da+hra);
np=(gp-pf-cf);
}
void payslip()
{
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("PAY SLIP");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Basic Pay :"+bp);
System.out.println("Dearness Allowance :"+da);
System.out.println("House Rent Allowance :"+hra);
System.out.println("PF :"+pf);
System.out.println("Staff Club Funds :"+cf);
System.out.println("Gross Pay :"+gp);
System.out.println("Net Pay :"+np);
}
}
class Programmer extends Employee
{
void get_bp()
{
System.out.print("Enter the basic pay: ");
bp=sc.nextDouble();
}
}
class Assistant_Professor extends Employee
{
void get_bp()
{
System.out.print("Enter the basic pay: ");
bp=sc.nextDouble();
}
}
class Associate_Professor extends Employee
{
void get_bp()
{
System.out.print("Enter the basic pay: ");
bp=sc.nextDouble();
}
}
class Professor extends Employee
{
void get_bp()
{
System.out.print("Enter the basic pay: ");
bp=sc.nextDouble(); }}
class Employee_Details
{
public static void main(String args[])
{
int des;
Scanner d=new Scanner(System.in);
Employee e=new Employee();
Programmer pr=new Programmer();
Assistant_Professor ap=new Assistant_Professor();
Associate_Professor asp=new Associate_Professor();
Professor p=new Professor();
System.out.println("EMPLOYEE PAY SLIP");
System.out.println(".........................");
Employee s;
do
{
System.out.println("\nDESIGNATIONS\n1.Programmer\n2.Assistant Professor\
n3.Associate Professor\n4.Professor\n5.Exit");
System.out.print("Enter Designation:");
des=d.nextInt();
switch(des)
{
case 1:
System.out.println("\nPROGRAMMER");
s=pr;
s.getdata();
pr.get_bp();
s.display();
s.calcualte();
s.payslip();
break;
case 2:
System.out.println("\nASSISTANT PROFESSOR");
s=ap;
s.getdata();
ap.get_bp();
s.display();
s.calcualte();
s.payslip();
break;
case 3:
System.out.println("\nASSOCIATE PROFESSOR");
s=asp;
s.getdata();
asp.get_bp();
s.display();
s.calcualte();
s.payslip();
break;
case 4:
System.out.println("\n1PROFESSOR");
s=p;
s.getdata();
p.get_bp();
s.display();
s.calcualte();
s.payslip();
break;
case 5:
System.out.println("Thank you!");
}
}while(des!=5); } }
OUTPUT:

RESULT:

The program to generate employee payslip was successfully executed.


EXPT NO:9 IMPLEMENTATION OF ABSTRACT CLASS AND
METHOD OVERRIDING

AIM: To implement abstract class methods and method overriding.

OBJECTIVE: To understand the concept of abstract class and method overriding.

SOFTWARE REQUIRED: Netbeans IDE

ALGORITHM:

STEP 1 : Start

STEP 2: Create an abstract class Shape with two data members length1, length2 and
aabstract methods printarea() and getdata().

STEP 3: Derive 3 classes Rectangle, Triangle, Circle from Shape class and define the
methods getdata() and printarea() in each subclass.

(Main class)

STEP 4: Using object r, call the methods of the Rectangle class.

STEP 5: Using object t, call the methods of Triangle class.

STEP 6: Using object c, call the methods of Circle class.

STEP 7: Stop

getdata() method:

class Rectangle:

STEP 1: Read the values of length1 and length2 for length and breadth.

class Triangle:

STEP 1: Read the values of length1 and length2 for base and height.

Class Circle:

STEP 1: Read the value of length1 for radius.


printarea() method:

class Rectangle:

STEP 1: Compute the area of rectangle as length1*length2 and display it.

class Triangle:

STEP 1: Compute the area of triangle as length1*length2*0.5 and display it.

class Circle:

STEP 1: Compute the area of circle as 3.14*length1*length1 and display it.

PROGRAM:

import java.io.*;

import java.util.*;

abstract class shape

int length1;

int length2;

abstract public void printarea();

abstract public void getdata();

static display()

System.out.println("displaying abstract class.....");

class rectangle extends shape

Scanner sc=new Scanner(System.in);

public void getdata()


{

System.out.println("enter lenght 1(for rectangle): ");

length1=sc.nextInt();

System.out.println("enter lenght 2(for rectangle): ");

length2=sc.nextInt();

public void printarea()

int area_rectangle=(length1*length2);

System.out.println("displaying area: "+area_rectangle);

class triangle extends shape

Scanner sc=new Scanner(System.in);

public void getdata()

System.out.println("enter lenght 1(for triangle): ");

length1=sc.nextInt();

System.out.println("enter lenght 2(for triangle): ");

length2=sc.nextInt();

public void printarea()

double area_triangle=(length1*length2*0.5);

System.out.println("displaying area: "+area_triangle);

}
}

class circle extends shape

Scanner sc=new Scanner(System.in);

public void getdata()

System.out.println("enter lenght 1(radius for circle): ");

length1=sc.nextInt();

public void printarea()

double area_circle=(3.14*length1*length1);

System.out.println("displaying area: "+area_circle);

public class main

public static void main(String[] args)

rectangle r=new rectangle();

triangle t=new triangle();

circle c=new circle();

shape.display();

r.getdata();

r.printarea();

t.getdata();

t.printarea();
c.getdata();

c.printarea();

OUTPUT:

RESULT:

The program to implement abstract class and method overriding was successfully
executed.

You might also like