-
Notifications
You must be signed in to change notification settings - Fork 5
/
Experiment5.java
39 lines (37 loc) · 1.2 KB
/
Experiment5.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*******************************************************************
* File : Experiment
* Author: Name
* Date : DD/MM/YYYY
*******************************************************************/
import java.util.Scanner;
class Employeee {
Scanner sc = new Scanner(System.in);
int basicSalary;
double DA,HRA,grossSalary;
// to display gross salary of engineer
void display() {
System.out.println("Gross salary of engineer is "+grossSalary);
}
// for calculating gross salary
void calcSalary() {
grossSalary = basicSalary+ DA*basicSalary*0.01 + HRA* basicSalary*0.01;
}
// for reading data from user
void readData() {
System.out.println("Enter basic salary of Engineer :");
basicSalary = sc.nextInt();
System.out.println("Enter DA of the Engineer : ");
DA=sc.nextFloat();
System.out.println("Enter HRA of the Engineer : ");
HRA=sc.nextFloat();
}
}
class Engineer extends Employeee {} //inherits attributes and methods from class Employeee
public class Experiment5 {
public static void main(String[] args) {
Engineer engineer = new Engineer(); // creating an object of Engineer
engineer.readData();
engineer.calcSalary();
engineer.display();
}
}