Skip to main content

simple basic object oriented java code for employee salary calculation

import java.io.*;
import java.util.Scanner;

public class Employees {
    Scanner scan=new Scanner(System.in);
    String Fname;   int EmpID;  int DOB; double Allowance;   double Salary;

    public void getDetails(){
  System.out.println("Enter the first name");
  Fname=scan.next();
  System.out.println("Enter the ID number");
  EmpID=scan.nextInt();
  System.out.println("Enter the date of birth");
  DOB=scan.nextInt();
  System.out.println("Enter the salary");
  Salary=scan.nextDouble();

  Allowance=0.6*Salary;
    }
   public void printReport(){
   System.out.println(Fname+"\t"+EmpID+"\t"+calGross()+"\t"+calPayee()+"\t"+calNetIncome());


   }
   public double calGross(){
       return Salary + Allowance;

   }
   public double calPayee(){
       double x=Salary+Allowance;
        if(x>50000)
            return 0.4*(Salary-50000)+7000;
        else
        if(x>40000)
            return 0.3*(Salary-40000)+4000;
        else
        if(x>30000)
            return 0.25*(Salary-30000)+1500;
        else
        if(x>20000)
            return 0.15*(Salary-50000);
        else
            return 0;

   }
   public double calNetIncome(){
       return calGross()-calPayee();

   }

   public static void main(String []args)throws IOException{
       Employees E[]=new Employees[2];//or []E

       int i;
double totnetincome=0,totpayee=0;

       for(i=0;i<E.length;i++){
           E[i]=new Employees();
           E[i].getDetails();
totnetincome+=E[i].calNetIncome();
totpayee+=E[i].calPayee();
       }
System.out.println("Name\t EMpID No\tGross \tPayee \tNetincome");
       for(i=0;i<E.length;i++){
           E[i].printReport();

       }
       System.out.println("Total netIncome "+totnetincome+"Total payee
"+totpayee);
   }//end of main
}//end of class

Comments

  1. Can we change the program with the current (and changing) salary payment norms of the company? Isn't the program lacking any factor which is used to calculate the salary?

    Thanks in advance!
    Jimmie Menon
    Payroll Providers Guelph

    ReplyDelete
    Replies
    1. Hi, hoping i understood your question, you could add setXYZ() and getXYZ() methods in the class to take care of changing variables. You could also set default values to be used when such values are not set. This is just a simple class and you are free to add any other factors matching your solution.

      Delete
  2. Really Nice Information,Thank You Very Much For Sharing.
    Web Development Company

    ReplyDelete
  3. Java is very good blog,it's highly professional course.Thanks for sharing
    java online course

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Your article is amazing.just love it. you might be interested in :chameleon run apk

    ReplyDelete
  6. Nice and good post. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information.


    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai


    ReplyDelete
  7. ountain Duck Keygen is a nifty OS X app that can make managing cloud storage accounts and FTP, SFTP, or WebDAV servers a lot easier, as it.Mountain Duck Encryption

    ReplyDelete

Post a Comment

Popular posts from this blog

Ten output devices, advantages and disadvantages, inter-site back-up mechanism, Expert systems for medical diagnosis,information systems security

(i)Printer Printer enables us to produce information output on paper. It is one of the most popular computer output devices we often use to get information on paper - called hard copy. Advantage They produce high quality paper output for presentation at a speedy rate. It is also possible to share the printer among different users in a network. Disadvantage The cost for maintenance of the printer equipment as well printing ink is cumulatively high. (ii) Plotters These devices are used to produce graphical outputs on paper. They have automated pens that make line drawings on paper Advantage They can produce neat drawings on a piece of paper based on user commands. In Computer Aided Design (CAD) they are used to produce paper prototypes that aid in design of the final system. Disadvantage They are more expensive than printers. Further, the command based interface is difficult to use. (iii)Monitor It is...

Start Wamp server on windows automatically permanently

For those that have completely refused to use linux platforms for development, you might find this useful. As with all (aspiring) web developers, it’s always important to test your projects locally before putting it out there for the entire web community to see. One must-have developer tool for this purpose is WAMPServer. We’ve all wished it’s automatically up and running when we need it. These easy steps will help you automate WAMPServer to run on system start-up. For those unfamiliar with WAMPServer, it is a development package that lets you run web development projects locally. WAMP stands for Windows, Apache, MySQL, PHP/Perl/Python. It’s basically four programs packaged to work as one. WAMP basically turns any Windows PC into a localized web server. The Linux counterpart is called LAMP, obviously. Once WAMPServer is installed in your PC, you’ll be able to test your web projects before putting it into the live environment. But I always found it a hassle to manually s...