Oops Manual 7,8,9
Oops Manual 7,8,9
ALGORITHM:
STEP 1 : Start
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.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.
dequeue() method:
display() method:
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
{
RESULT:
ALGORITHM:
STEP 1 : Start
(Main class)
STEP 4: Create a main class and display the designation for which payslip has to be
calculated and read choice.
STEP 6.5: If all the cases are false then display Wrong Input and Exit.
STEP 7: Stop
getdata() method:
display() method:
get_bp() method:
calculate() method:
payslip() method:
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:
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 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:
class Rectangle:
class Triangle:
class Circle:
PROGRAM:
import java.io.*;
import java.util.*;
int length1;
int length2;
static display()
length1=sc.nextInt();
length2=sc.nextInt();
int area_rectangle=(length1*length2);
length1=sc.nextInt();
length2=sc.nextInt();
double area_triangle=(length1*length2*0.5);
}
}
length1=sc.nextInt();
double area_circle=(3.14*length1*length1);
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.