Martin your friend has declared a class called Employee with the following members; Employee ID, Employee Name, Basic Salary, Allowance, and Net Salary. a) Write a code for a member function called get_input that will be used for data input. (3 Marks) b) Write a code for a member function called Calculate that will be used to calculate net salary as the sum of basic salary and allowances. (2 Marks) c) Write a code for the default constructor that will assign values to the variables in the Employee class. (3 Marks) d) Write a code for the default constructor. (3 Marks) e) Write a complete program that captures and includes all the details in (a-d) above. Run the code and show your output.
import java.util.Scanner;
class Employee {
private String emoployeeName;
private int basicSalary;
private int allowance;
private int netSalary;
public Employee() {}
public Employee(String a, int b, int c, int d){
employeeName = a;
basicSalary = b;
allowance = c;
netSalary = d;
}
public void calculate() {
allowance = basicSalary + newSalary;
}
public void getInput() {
Scanner s = new Scanner(System.in);
basicSalary = s.nextInt();
netSalary = s.nextInt();
}
}
Comments
Leave a comment