Search This Blog

Saturday 10 May 2014

Java Program to Calculate Salary of an Employee using hierarchical inheritance.

import java.util.*;
import java.io.*;
class Employee
{
    int age;
    String name, address, gender;
    DataInputStream get = new DataInputStream(System.in);
    Employee()throws IOException
    {
        System.out.println("Enter Name of the Employee:");
        name = get.readLine();
        System.out.println("Enter Gender of the Employee:");
        gender = get.readLine();
        System.out.println("Enter Address of the Employee:");
        address = get.readLine();
        System.out.println("Enter Age:");
        age = Integer.parseInt(get.readLine());;
    }

    void display()
    {
        System.out.println("Employee Name: "+name);
        System.out.println("Age: "+age);
        System.out.println("Gender: "+gender);
        System.out.println("Address: "+address);
    }
}

class FullTime extends Employee
{
    float salary;
    String des;

    FullTime()throws IOException
    {
        System.out.println("Enter Designation:");
        des = get.readLine();
        System.out.println("Enter Salary:");
        salary = Float.valueOf(get.readLine()).floatValue();
    }
    void display()
    {
        System.out.println("================================");
        System.out.println("Full Time Employee Details");
        System.out.println("================================");
        super.display();
        System.out.println("Salary: Rs."+salary);
        System.out.println("Designation: "+des);
    }
}

class PartTime extends Employee
{
    int workinghrs, rate;
    PartTime()throws IOException
    {
        System.out.println("Enter Number of Working Hours:");
        workinghrs = Integer.parseInt(get.readLine());
    }
    void calculatepay()
    {
        rate = 200 * workinghrs;
    }

    void display()
    {
        System.out.println("==============================");
        System.out.println("Part Time Employee Details");
        System.out.println("==============================");
        super.display();
        calculatepay();
        System.out.println("Number of Working Hours: "+workinghrs);
        System.out.println("Salary for "+workinghrs+" working hours is: Rs."+rate);
    }
}

class MainEmp
{
    public static void main(String args[]) throws IOException
    {
        System.out.println("================================");
        System.out.println("Enter Full Time Employee Details");
        System.out.println("================================");
        FullTime full = new FullTime();
        System.out.println("================================");
        System.out.println("Enter Part Time Employee Details");
        System.out.println("================================");
        PartTime part = new PartTime();
        full.display();
        part.display();
    }
}

4 comments :

  1. I prefer to study this kind of material. Nicely written information in this post, the quality of content is fine and the conclusion is lovely. Things are very open and intensely clear explanation of issues
    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  2. After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
    Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in




    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  3. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me. I am a regular follower of your blog.
    Really very informative post you shared here. Kindly keep blogging.
    Java training in Btm layout
    Java training in Rajaji nagar
    Java training in Kalyan nagar
    Java training in Kalyan nagar
    Java training in Jaya nagar






    ReplyDelete
  4. Thanks For Sharing The information The Information Shared Is Very Valuable Please Keep Updating us The Information shared Is Very Valuable Python Online Course Data Science Online Course Aws Online Course

    ReplyDelete

FREE Hit Counters