File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Employee {
2
+ private String name ;
3
+ private double basicSalary ;
4
+
5
+ public Employee (String name , double basicSalary ) {
6
+ this .name = name ;
7
+ this .basicSalary = basicSalary ;
8
+ }
9
+
10
+ public double calculateAnnualSalary () {
11
+ double tax = basicSalary * 0.10 ;
12
+ double bonus = basicSalary * 0.02 ;
13
+ double travellingAllowance = basicSalary * 0.015 ;
14
+
15
+ double monthlySalary = basicSalary - tax + bonus + travellingAllowance ;
16
+ return monthlySalary * 12 ; // Annual salary
17
+ }
18
+
19
+ public String getName () {
20
+ return name ;
21
+ }
22
+
23
+ public double getBasicSalary () {
24
+ return basicSalary ;
25
+ }
26
+ }
27
+
28
+ public class EmployeeSalaryCalculator {
29
+ public static void main (String [] args ) {
30
+ if (args .length < 2 ) {
31
+ System .out .println ("Enter name and basic salary in Command Prompt" );
32
+ return ;
33
+ }
34
+
35
+ String name = args [0 ];
36
+ double basicSalary = Double .parseDouble (args [1 ]);
37
+
38
+ Employee employee = new Employee (name , basicSalary );
39
+ double annualSalary = employee .calculateAnnualSalary ();
40
+
41
+ System .out .println ("Employee Name: " + employee .getName ());
42
+ System .out .println ("Basic Salary: " + employee .getBasicSalary ());
43
+ System .out .println ("Annual Salary (after applying tax, bonus, and travelling allowance): " + annualSalary );
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments