-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonUtils.java
More file actions
53 lines (38 loc) · 1.56 KB
/
Copy pathCommonUtils.java
File metadata and controls
53 lines (38 loc) · 1.56 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
package salarySlip;
import java.util.ResourceBundle;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;
public class CommonUtils{
ResourceBundle rb = ResourceBundle.getBundle("constants");
Locale locale = new Locale(rb.getString("localeFormat"),rb.getString("localeCountry")); // taking values from file
// instead of hard coded input
// idk why I was stuck here for 1 hour and it runs at the end unexpectedly
// Error - Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name
// formatting name-------------------------------------
public String getProperName(String name) {
String names[] = name.split(" ");
String fullName = "";
for(String x : names) {
fullName+=String.valueOf(x.charAt(0)).toUpperCase()+x.substring(1).toLowerCase()+" ";
}
return fullName;
}
// formatting salary ------------------------------
public String formatSalary(double salary) {
// Locale locale = new Locale("hi","IN");
NumberFormat nf = NumberFormat.getCurrencyInstance(locale); // no new object is made
String formatsal = nf.format(salary);
return formatsal;
}
// formatting the date
public String formatDate() {
// Locale locale = new Locale("hi","IN");
// did this because it's easy for client to edit the settings
Date date = new Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale); // no new object is made
String formatdate = df.format(date);
return formatdate;
}
}