0% found this document useful (0 votes)
40 views7 pages

Exp 3

The document describes a Java program that: 1) Creates an Employee abstract class with member variables for name, ID, address, email, and phone number. 2) Inherits from Employee to create Programmer, Assistant Professor, Associate Professor, and Professor classes. 3) Adds a basic pay (BP) member variable to the inherited classes and calculates deductions like DA, HRA, PF from BP. 4) Generates pay slips for employees showing gross and net salary by creating objects for the inherited classes and calling display methods.

Uploaded by

MANI KANDAN
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)
40 views7 pages

Exp 3

The document describes a Java program that: 1) Creates an Employee abstract class with member variables for name, ID, address, email, and phone number. 2) Inherits from Employee to create Programmer, Assistant Professor, Associate Professor, and Professor classes. 3) Adds a basic pay (BP) member variable to the inherited classes and calculates deductions like DA, HRA, PF from BP. 4) Generates pay slips for employees showing gross and net salary by creating objects for the inherited classes and calling display methods.

Uploaded by

MANI KANDAN
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/ 7

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.

Use the algorithm below: 1. Start 2. Create the class Employee with name,
Empid, address, mailid, mobileno as data members. 3. Inherit the classes
Programmer, Asstprofessor, Associateprofessor and Professor from
employee class. 4. Add Basic Pay (BP) as the member of all the inherited
classes. 5. Calculate DA as 97% of BP,HRA as 10% of BP, PF
as 12% of BP, Staff club fund as 0.1% of BP. 6. Calculate gross salary
and net salary. 7. Generate payslip for all categories of employees. 8.
Create the objects for the inherited classes and invoke the necessary
methods to display the Payslip
import java.util.Scanner;
class Employee{
String Emp_name;
int Emp_id;
String Address;
String Mail_id;
int Mobile_no;
void display(){
System.out.println(Emp_name);
//Syetem.out.println(Address);
System.out.println(Emp_id);
System.out.println(Mail_id);
System.out.println(Mobile_no);
}
}
class Programmer extends Employee{
int BP;
//for understanding
/*int DA= (int) (0.97*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);
System.out.println("SATFF CLUD FUND"+0.001*BP);

}
}
class Assistant_Professor extends Employee{
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("SATFF CLUD FUND"+0.001*BP);
}
}
class Associate_Professor extends Employee{
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("SATFF CLUD FUND"+0.001*BP);

}
}
class Professor extends Employee{
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("SATFF CLUD FUND"+0.001*BP);

}
}
class Main{
public static void main(String args[]){
System.out.println("\n 1.Programmer\n2.Assistant_Professor\
n3.Associate_Professor\n4.Professor");
Scanner input=new Scanner(System.in);
System.out.print("Enter an integer: ");
int ch=input.nextInt();
//use switch case for opt
switch (ch) {
case 1:
Employee e1=new Employee();
Programmer p1=new Programmer();
e1.Emp_name="ABC";
e1.Address="y-city";
e1.Mail_id="praw";
e1.Emp_id=567;
e1.Mobile_no=2345678;
p1.BP=15000;
p1.display();
e1.display();
break;
case 2:
Employee e2=new Employee();
Assistant_Professor p2=new Assistant_Professor();
e2.Emp_name="DEF";
e2.Address="A-city";
e2.Mail_id="RAJAN";
e2.Emp_id=123;
e2.Mobile_no=987321;
p2.BP=30000;
p2.display();
e2.display();
break;
case 3:
Employee e3=new Employee();
Associate_Professor p3=new Associate_Professor();
e3.Emp_name="GHF";
e3.Address="B-city";
e3.Mail_id="MAIN";
e3.Emp_id=456;
e3.Mobile_no=98710;
p3.BP=30000;
p3.display();
e3.display();
break;
case 4:
Employee e4=new Employee();
Professor p4=new Professor();
e4.Emp_name="KANNAN";
e4.Address="TRICHY";
e4.Mail_id="kanna";
e4.Emp_id=789;
e4.Mobile_no=9810;
p4.BP=30000;
p4.display();
e4.display();
break;
case 5:
//exit(1);

default:
System.out.println("enter correct choice");

}
}
}

Aim:
Write a Java program to create an abstract class named Shape that contains
two integers and an empty method named print Area (). 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 print Area () that prints the area of the given shape.

Source Code:

AreaOfShapes.java

package oops.lab;

import java.util.*;

abstract class Shape {


public int x, y;

public abstract void printArea();


}

class Rectangle1 extends Shape {

public void printArea() {


float area;
area = x * y;
System.out.println("Area of Rectangle is " + area);
}
}

class Triangle extends Shape {

public void printArea() {


float area;
area = (x * y) / 2.0f;
System.out.println("Area of Triangle is " + area);
}
}

class Circle extends Shape {

public void printArea() {


float area;
area = (22 * x * x) / 7.0f;
System.out.println("Area of Circle is " + area);
}
}

public class AreaOfShapesExp4 {

public static void main(String[] args) {


int choice;
Scanner sc = new Scanner(System.in);

do {
System.out.println("Menu \n 1.Area of Rectangle \n
2.Area of Traingle \n 3.Area of Circle \n 4.Exit");
System.out.print("Enter your choice : ");
choice = sc.nextInt();

switch (choice) {
case 1:
System.out.println("Enter length and breadth for
area of rectangle : ");
Rectangle1 r = new Rectangle1();
r.x = sc.nextInt();
r.y = sc.nextInt();
r.printArea();
break;
case 2:
System.out.println("Enter bredth and height for
area of traingle : ");
Triangle t = new Triangle();
t.x = sc.nextInt();
t.y = sc.nextInt();
t.printArea();
break;
case 3:
System.out.println("Enter radius for area of
circle : ");
Circle c = new Circle();
c.x = sc.nextInt();
c.printArea();
break;
default:
System.out.println("Enter correct choice");
}
} while (choice < 4);
}
}

Output:

Menu

1.Area of Rectangle

2.Area of Traingle

3.Area of Circle

4.Exit

Enter your choice : 1


Enter length and breadth for area of rectangle :

55

66

Area of Rectangle is 3630.0

Menu

1.Area of Rectangle

2.Area of Traingle

3.Area of Circle

4.Exit

Enter your choice : 2

Enter bredth and height for area of traingle :

585

55

Area of Triangle is 16087.5

Menu

1.Area of Rectangle

2.Area of Traingle
3.Area of Circle

4.Exit

Enter your choice : 3

Enter radius for area of circle :

55

Area of Circle is 9507.143

Menu

1.Area of Rectangle

2.Area of Traingle

3.Area of Circle

4.Exit

Enter your choice : 4

Enter correct choice

You might also like