KnowledgeBoat Logo

Computer Applications

Define a class with the following specifications

Class name : employee

Member variables
eno : employee number
ename : name of the employee
age : age of the employee
basic : basic salary (Declare the variables using appropriate data types)

Member methods
void accept( ) : accept the details using scanner class
void calculate( ) : to calculate the net salary as per the given specifications

net = basic + hra + da - pf
hra = 18.5% of basic
da = 17.45% of basic
pf = 8.10% of basic

if the age of the employee is above 50 he/she gets an additional allowance of ₹5000

void print( ) : to print the details as per the following format

eno ename age basic net

void main( ) : to create an object of the class and invoke the methods

Java

Java Classes

31 Likes

Answer

import java.util.Scanner;

public class employee
{
    private int eno;
    private String ename;
    private int age;
    private double basic;
    private double net;
    
    public void accept() 
    {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter name : ");
        ename = in.nextLine();
        System.out.print("Enter employee no : ");
        eno = in.nextInt();
        System.out.print("Enter age : ");
        age = in.nextInt();
        System.out.print("Enter basic salary : ");
        basic = in.nextDouble();
    }
    public void calculate()
    {
        double hra, da, pf;
        hra = 18.5/100.0 * basic;
        da = 17.45/100.0 * basic;
        pf = 8.10/100.0 * basic;
        net = basic + hra + da - pf;
        if(age > 50)
            net += 5000;
    }
    
    public void print()
    {
        System.out.println(eno + "\t" + ename + "\t" + age + "\t Rs."
        + basic + "\t Rs." + net );
    }
    
    public static void main(String args[])
    {
        employee ob = new employee();
        ob.accept();
        ob.calculate();
        ob.print();
    }
}

Output

BlueJ output of Define a class with the following specifications Class name : employee Member variables eno : employee number ename : name of the employee age : age of the employee basic : basic salary (Declare the variables using appropriate data types) Member methods void accept( ) : accept the details using scanner class void calculate( ) : to calculate the net salary as per the given specifications net = basic + hra + da - pf hra = 18.5% of basic da = 17.45% of basic pf = 8.10% of basic if the age of the employee is above 50 he/she gets an additional allowance of ₹5000 void print( ) : to print the details as per the following format eno ename age basic net void main( ) : to create an object of the class and invoke the methods

Answered By

15 Likes


Related Questions