forked from tejaspundpal/Java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp3_Employee.java
More file actions
107 lines (103 loc) · 3.01 KB
/
Copy pathexp3_Employee.java
File metadata and controls
107 lines (103 loc) · 3.01 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
106
107
package college_programs;
import java.util.*;
class employeetest
{
String first_name;
String last_name;
float salary;
employeetest()
{
first_name ="NULL";
last_name ="NULL";
salary = 0f;
}
String getFirst_name()
{
return first_name;
}
String getLast_name()
{
return last_name;
}
float getSalary()
{
return salary;
}
void setFirst_name(String first_name)
{
this.first_name = first_name;
}
void setLast_name(String last_name)
{
this.last_name = last_name;
}
void setSalary(float salary)
{
if(salary < 0){
this.salary=0f;
}
else {
this.salary = salary;
}
}
float yearlySalary(float salary)
{
return (float)12 * salary;
}
float raisedSalary(float yearly_salary)
{
return yearly_salary+((float)10/100)*yearly_salary;
}
}
public class exp3_Employee
{
void setData(employeetest em)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter First Name : ");
String fn = sc.nextLine();
em.setFirst_name(fn);
System.out.println("Enter last Name : ");
String ln = sc.nextLine();
em.setLast_name(ln);
System.out.println("Enter monthly salary : ");
float s = sc.nextFloat();
em.setSalary(s);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
employeetest e = new employeetest();
employeetest e1 = new employeetest();
exp3_Employee E = new exp3_Employee();
exp3_Employee E1 = new exp3_Employee();
System.out.println("Enter information of first employee...");
E.setData(e);
System.out.println("Enter information of second employee...");
E1.setData(e1);
while(true) {
System.out.println("1)Get yearly salary of 1st Employee\n2)Get yearly salary of 1st Employee after raising\n3)Get yearly salary of 2nd Employee\n4)Get yearly salary of 2nd Employee after raising\n5)Exit");
System.out.println("Enter your choice: ");
int choice = sc.nextInt();
switch (choice){
case 1->{
System.out.println("yearly salary : "+e.yearlySalary(e.getSalary()));
}
case 2->{
System.out.println("yearly salary after raised : "+e.raisedSalary(e.yearlySalary(e.getSalary())));
}
case 3->{
System.out.println("yearly salary : "+e1.yearlySalary(e1.getSalary()));
}
case 4->{
System.out.println("yearly salary after raised : "+e1.raisedSalary(e1.yearlySalary(e1.getSalary())));
}
case 5->{
System.exit(0);
}
default -> {
System.out.println("Invalid choice...!!");
}
}
}
}
}