Answer to Question #228715 in Java | JSP | JSF for swastica k g

Question #228715

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.


1
Expert's answer
2021-08-23T12:21:01-0400
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);


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS