Exp 3
Exp 3
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.*;
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
55
66
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
585
55
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit
55
Menu
1.Area of Rectangle
2.Area of Traingle
3.Area of Circle
4.Exit