Write a program to calculate gross and net pay of employee from
basic salary. Create employee class which consists of employee
name, emp_id, and basic salary as its data members. Use
parameterized constructor in the derived class to initialize data
members of the base class and calculate gross and net pay of the
employee in the derived class.
import java.util.Scanner;
public class Employee {
private String name;
private long emp_id;
private int basic_salary;
public Employee(String name, long emp_id, int basic_salary) {
this.name = name;
this.emp_id = emp_id;
this.basic_salary = basic_salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getEmp_id() {
return emp_id;
}
public void setEmp_id(long emp_id) {
this.emp_id = emp_id;
}
public int getBasic_salary() {
return basic_salary;
}
public void setBasic_salary(int basic_salary) {
this.basic_salary = basic_salary;
}
@Override
public String toString() {
return "Emploee [name=" + name + ", emp_id=" + emp_id + ", basic_salary=" + basic_salary + "]";
}
public void calculate_gross_pay(int hours) {
int result = hours * basic_salary;
System.out.println("Gross pay is: " + result);
}
public void calculate_net_pay(int hours, int tax_percent) {
double result = (hours * basic_salary) - (((hours * basic_salary) * tax_percent) / 100);
System.out.println("Gross pay is: " + result);
}
public static void main(String[] args) {
int hours = 0;
int tax = 0;
Scanner scan = new Scanner(System.in);
System.out.println("Please provide how many hours work emploee in this month: ");
hours = scan.nextInt();
System.out.println("Please provide tax rate on this State: ");
tax = scan.nextInt();
scan.close();
Employee empl = new Employee("Frank", 12890451, 25);
empl.calculate_gross_pay(hours);
empl.calculate_net_pay(hours, tax);
}
}
Comments
Leave a comment