-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
96 lines (77 loc) · 2.33 KB
/
Copy pathMain.java
File metadata and controls
96 lines (77 loc) · 2.33 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
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
class Employee {
private String name;
private String mail;
private int age;
private int salary;
// Getter methods
public String getName() {
return name;
}
public String getMail() {
return mail;
}
public int getAge() {
return age;
}
public int getSalary() {
return salary;
}
// Setter methods
public void setName(String name) {
this.name = name;
}
public void setMail(String mail) {
this.mail = mail;
}
public void setAge(int age) {
this.age = age;
}
public void setSalary(int salary) {
this.salary = salary;
}
// Method to write employee data to file
public void employee_data() {
try {
if (salary <= 20000) {
FileWriter employee_data = new FileWriter("employees.txt", true);
employee_data.write(name + " " + mail + " " + age + " " + salary + "\n");
employee_data.close();
} else {
System.out.println("The Salary is more than the limit. Please enter again.");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
public class Main {
public static void main(String[] args) {
Employee data_pass = new Employee();
Scanner emp_data = new Scanner(System.in);
int i = 0;
while (i < 10) {
System.out.println("Please enter your name: ");
String name_data = emp_data.nextLine();
System.out.println("Please enter your email: ");
String mail_data = emp_data.nextLine();
System.out.println("Age: ");
int age_data = emp_data.nextInt();
System.out.println("Salary: ");
int salary_data = emp_data.nextInt();
emp_data.nextLine();
// Setting employee data using setter methods
data_pass.setName(name_data);
data_pass.setMail(mail_data);
data_pass.setAge(age_data);
data_pass.setSalary(salary_data);
// Writing employee data to file
data_pass.employee_data();
i++;
}
emp_data.close();
}
}