-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLab3.java
More file actions
68 lines (60 loc) · 1.71 KB
/
Lab3.java
File metadata and controls
68 lines (60 loc) · 1.71 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
// 3: A class called Employee which models am employee with an id, name and salary is designed as shown in the class diagram.
// the method raiseSalary(percentage) increases the salary by the given percentage.
// Develop the employee class and suitable main method to demonstration.
import java.util.Scanner;
class Employee {
String id, name;
double salary, percentage;
void read() {
Scanner s = new Scanner(System.in);
System.out.println("Enter ID, Name, Salary");
id = s.next();
name = s.next();
salary = s.nextDouble();
}
void display() {
System.out.println(id + "\t" + name + "\t" + salary);
}
void raise(double percentage) {
salary += (percentage / 100) * salary;
}
}
public class Lab3 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the number of employee");
int n = s.nextInt();
Employee e[] = new Employee[n];
for (int i = 0; i < n; i++) {
e[i] = new Employee();
e[i].read();
}
System.out.println("ID\tName\tSalary\n");
for (int i = 0; i < n; i++)
e[i].display();
System.out.println("Enter percentage");
double per = s.nextDouble();
for (int i = 0; i < n; i++)
e[i].raise(per);
System.out.println("ID\tName\tSalary");
for (int i = 0; i < n; i++)
e[i].display();
}
}
/*
* Output:
* Enter the number of employee
* 2
* Enter ID, Name, Salary
* 1 A 1000
* Enter ID, Name, Salary
* 2 B 2000
* ID Name Salary
* 1 A 1000.0
* 2 B 2000.0
* Enter percentage
* 10
* ID Name Salary
* 1 A 1100.0
* 2 B 2200.0
*/