-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEmpSalarySlip.java
More file actions
105 lines (83 loc) · 3.11 KB
/
EmpSalarySlip.java
File metadata and controls
105 lines (83 loc) · 3.11 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Scanner;
public class EmpSalarySlip {
int id;
String name;
double basicSalary;
// Earnings
double hra = 0.40;
double da = 0.20;
double ta = 0.25;
double ma = 0.15;
// Deductions
double pf = 0.05;
double tds = 0.10;
/*
* public EmpSalarySlip(int id, String name, double salary) {
* this.id = id;
* this.name = name;
* this.salary = salary;
* }
*/
void takeInput() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your ID : ");
this.id = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter your Name : ");
this.name = scanner.nextLine();
EmpUtils utils = new EmpUtils();
name = utils.formatName(name);
System.out.println("Enter your Salary : ");
this.basicSalary = scanner.nextDouble();
//name.toUpperCase();
// get first letter of name
//char firstLetter = name.charAt(0);
// type cast character into String and convert to upper case
//String first = String.valueOf(firstLetter).toUpperCase();
// convert remaining string into lower case
//String remainingString = name.substring(1).toLowerCase();
//name = first + remainingString;
// name = "raM kuMAr ShaRMA";
String nameArray[] = name.split(" ");
// nameArray = {"raM", "kuMAr", "ShaRMA"};
String fullName = "";
for(String n : nameArray) {
// get first letter of name
char firstLetter = n.charAt(0);
// type cast character into String and convert to upper case
String first = String.valueOf(firstLetter).toUpperCase();
// convert remaining string into lower case
String remainingString = n.substring(1).toLowerCase();
n = first + remainingString;
fullName = fullName + n + " ";
}
scanner.close();
}
void showEmpDetails() {
System.out.println("ID : " + id);
System.out.println("Name : " + name);
System.out.println("Salary : " + basicSalary);
}
public double earnings() {
hra = hra * basicSalary;
da = da * basicSalary;
ta = ta * basicSalary;
ma = ma * basicSalary;
double earningSalary = hra + da + ta + ma + basicSalary;
return earningSalary;
}
public double deductions() {
pf = pf * basicSalary;
tds = tds * basicSalary;
double deductionSalary = pf + tds;
return deductionSalary;
}
public double netSalary() {
double earningSalary = earnings();
double deductionSal = deductions();
System.out.println("Earning : " + earningSalary);
System.out.println("Deduction : " + deductionSal);
double netSal = earningSalary - deductionSal;
return netSal;
}
}