How to calculate salary of Employee using inheritance in java




Hello everyone its nice to back again with these another java programming tutorial, in this post I will be showing you how to use inheritance altogether with the buffered reader approach, to allow us to input a "name of employee", "Number of working days", then the "Salary", so in these case, only the name of the employee is the "String "  data types, the rest are "int " data types including the method that I used within these articles. The code below is the illustration sample that you can test with your IDE, have a tried, then tell me what you can say about the coding and thanks... enjoy coding.



import java.io.*;
class Employee{
public static String Name_of_Employee;
public static int Number_of_days;
public static int Salary;
public static int getResult;
public Employee()
{
getResult = Number_of_days*Salary;
}
public void printResult(){
System.out.println("Total Salary is:\t"+getResult);
}
}
class NewEmployee extends Employee{
public NewEmployee()
{
System.out.println("");
System.out.println("Your name is:"+Name_of_Employee);
}
public void workDaysNo()
{
System.out.println("Your total number of working days are:"+ Number_of_days);
}
public void salaryRate()
{
System.out.println("Your salary is:"+Salary);
}
}
public class NewHiredEmployee extends NewEmployee
{
public NewHiredEmployee()
{
System.out.println("");
}
public void salaryRates()
{
System.out.println("");
}
public static void main(String[]args)throws IOException{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a name of Employee\t");
Name_of_Employee = input.readLine();
System.out.println("Enter a number of working days:\t");
Number_of_days = Integer.parseInt(input.readLine());
System.out.println("Enter a Salary Rate:\t");
Salary = Integer.parseInt(input.readLine());
NewHiredEmployee SelfEmployed = new NewHiredEmployee();
SelfEmployed.workDaysNo();
SelfEmployed.printResult();
SelfEmployed.salaryRates();
}
}

Post a Comment

0 Comments