Salary calculation program in java




















If valid, return true. Else, return false. In the main method, before invoking the findNetSalary method, validate the input by invoking the validateInput method.

Static method is a method in Java which are referenced with the class name itself and do not require separate object to reference it. For the given problem, static method can be used as a block which will be consisting of the main logic used to derive at the net salary of the employee. This is the block where the same logic used in the example of Scanner Class is used with the same arithmetic operation to be performed.

As it can be observed that, the return type of static method is double which is precisely the same as that of our desired net salary. This method first finds the exact amount of income tax , professional tax and provident fund. After obtaining these, it finds the net salary using. Command line arguments are where we can give input in the form of argument in the command prompt itself while running the java code. We can directly the values as arguments in command line while running the code with space in between.

Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search. The first 36 hours worked are paid at a rate of Since Java 7, it's recommend to use try-with-resources on AutoCloseable instances, e. Of course, you may want to perform extra validation, for example making sure that the input is a positive number.

The 41 is not immediately obvious from the problem statement, because that's really just adding the next 5 hours are paid You should avoid the hard-coding and instead rely more on declaring suitable constants so that it's easier to update these values in the future.

You can also avoid unnecessary subtractions and additions above the base hours to hoursWorked for the following reaons:. Since your approach is self-contained per if clause as opposed to a 'waterfall'-like approach , you can simply perform the one or two subtractions required to obtain the reminder hours for multiplication with the extra rates.

Also write a method : public static Employee getEmployeeDetails - which gets the employee details - id, name and salary, and returns the employee object. Improve this question.

Zabuzard Please clarify what it is you are stuck on. You can't have methods inside other methods. Sostart by removing those two empty methods. Don't try to print something, get an input, and set the employee ID in a single line. Those are three separate instructions, which should be on three separate lines: 1. Add a comment. Active Oldest Votes.

Improve this answer. Tal Angel Tal Angel 1 1 gold badge 17 17 silver badges 41 41 bronze badges. If you going to pass in a double i. You need to declare variables if you going to use them namelty pfamount needs to be declared as a double before you can assign something to it. You'll probably need a public String toString method, for printing out your employee object.

This is not the correct way to implement java.



0コメント

  • 1000 / 1000