Monday, May 8, 2017

Payroll Program in Java Using Getters and Setters


In this article I would like to share with you a simple payroll program that I wrote using Java it is an object oriented programming style with the use of getters and setters a concept of encapsulation and the creation of object. The code is very simple and easy to understand. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

package demo;

import java.util.Scanner;

public class Payroll {
int rate_per_day=0, no_of_days=0,emp_id=0;
String employees_name;
private int getRate_per_day() {
return rate_per_day;
}

private int getNo_of_days() {
return no_of_days;
}

private int getEmp_id() {
return emp_id;
}

private String getEmployees_name() {
return employees_name;
}

private void setRate_per_day(int rate_per_day) {
this.rate_per_day = rate_per_day;
}

private void setNo_of_days(int no_of_days) {
this.no_of_days = no_of_days;
}

private void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}

private void setEmployees_name(String employees_name) {
this.employees_name = employees_name;
}

public int process_Salary() {
return(no_of_days * rate_per_day);
}
public void display_Records(){
   System.out.println();
         System.out.println("===== DISPLAY RESULTS =====");
   System.out.println();
    System.out.println("Employee's ID         : "  + getEmp_id());
    System.out.println("Employee's Name       : "  + getEmployees_name());
    System.out.println("Number of Day's Work  : "  + getNo_of_days());
    System.out.println("Rate Per Day          :  " + getRate_per_day());
       System.out.println();
       System.out.println("Gross Salary          : Php " + process_Salary());
       System.out.println();
       System.out.print("\t END OF PROGRAM");
}

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
 
  Payroll emp = new Payroll();
  
      System.out.println();
      System.out.println("Payroll Program in Java Using Getters and Setters");
      System.out.println();
      System.out.print(" Employee's ID Number : ");
      emp.emp_id = input.nextInt();
      input.nextLine();
      System.out.print(" Employee's Name : ");
      emp.employees_name = input.nextLine();
       System.out.print(" Employee's Daily Rate : ");
      emp.rate_per_day = input.nextInt();
       System.out.print(" Number of Day's Work : ");
      emp.no_of_days = input.nextInt();
  
      emp.setEmp_id(emp.emp_id);
      emp.setEmployees_name(emp.employees_name);
      emp.setNo_of_days(emp.no_of_days);
      emp.setRate_per_day(emp.rate_per_day);
      
      emp.getEmp_id();
      emp.getEmployees_name();
      emp.getNo_of_days();
      emp.getRate_per_day();
      
       emp.display_Records();
  
input.close();

}

}



No comments:

Post a Comment