Skip to content
Open

lab2 #47

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/lab-java-standard-input-and-classes.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions employee.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
eertssty122000
eertssty122000
eertssty122000
Name: Ali Email: ali@mail.com Age: 25 Salary: 3500.0
Name: Leyla Email: leyla@mail.com Age: 28 Salary: 4200.0
Name: Murad Email: murad@mail.com Age: 30 Salary: 5000.0
Name: Nigar Email: nigar@mail.com Age: 22 Salary: 2800.0
Name: Kamran Email: kamran@mail.com Age: 35 Salary: 6000.0
Name: Aysel Email: aysel@mail.com Age: 27 Salary: 3900.0
Name: Rauf Email: rauf@mail.com Age: 40 Salary: 7500.0
Name: Sevda Email: sevda@mail.com Age: 24 Salary: 3100.0
Name: Tural Email: tural@mail.com Age: 29 Salary: 4700.0
Name: Gunel Email: gunel@mail.com Age: 26 Salary: 3600.0
Name: Ali Email: ali@mail.com Age: 25 Salary: 3500.0
Name: Leyla Email: leyla@mail.com Age: 28 Salary: 4200.0
Name: Murad Email: murad@mail.com Age: 30 Salary: 5000.0
Name: Nigar Email: nigar@mail.com Age: 22 Salary: 2800.0
Name: Kamran Email: kamran@mail.com Age: 35 Salary: 6000.0
Name: Aysel Email: aysel@mail.com Age: 27 Salary: 3900.0
Name: Rauf Email: rauf@mail.com Age: 40 Salary: 7500.0
Name: Sevda Email: sevda@mail.com Age: 24 Salary: 3100.0
Name: Tural Email: tural@mail.com Age: 29 Salary: 4700.0
Name: Gunel Email: gunel@mail.com Age: 26 Salary: 3600.0
Binary file not shown.
Binary file not shown.
Binary file not shown.
56 changes: 56 additions & 0 deletions src/main/java/lab2/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package lab2;

public class Employee {
private String name;
private String email;
private int age;
private double salary;

public Employee(String name, String email, int age, double salary) {
this.name = name;
this.email = email;
this.age = age;
this.salary = salary;
}

public String getName() {
return name;
}

public void setName(String name) {
if (name.trim().isEmpty() || name == null) {
throw new IllegalArgumentException("Name cannot be null or empty");
}
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
if (email == null || !email.matches("^[A-Za-z0-9+_.-]+@(.+)$")) {
throw new IllegalArgumentException("Invalid email address");
}
this.email = email;
}

public int getAge() {
return age;
}

public void setAge(int age) {
if (age < 18 || age > 100) {
throw new IllegalArgumentException("Invalid age");
}
this.age = age;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}
}
21 changes: 21 additions & 0 deletions src/main/java/lab2/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package lab2;

public class Intern extends Employee {

public static final double MAX_SALARY = 20000;

public Intern(String name, String email, int age, double salary) {
super(name, email, age, salary);
}

@Override
public void setSalary(double salary) {
if (salary > MAX_SALARY) {
throw new IllegalArgumentException("Salary exceeds maximum");
}
super.setSalary(salary);

}


}
64 changes: 64 additions & 0 deletions src/main/java/lab2/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package lab2;

import java.io.*;
import java.util.Scanner;

public class Main {

public static void main(String[] args) throws IOException {
Employee emp1 = new Employee("Ali", "ali@mail.com", 25, 3500);
Employee emp2 = new Employee("Leyla", "leyla@mail.com", 28, 4200);
Employee emp3 = new Employee("Murad", "murad@mail.com", 30, 5000);
Employee emp4 = new Employee("Nigar", "nigar@mail.com", 22, 2800);
Employee emp5 = new Employee("Kamran", "kamran@mail.com", 35, 6000);
Employee emp6 = new Employee("Aysel", "aysel@mail.com", 27, 3900);
Employee emp7 = new Employee("Rauf", "rauf@mail.com", 40, 7500);
Employee emp8 = new Employee("Sevda", "sevda@mail.com", 24, 3100);
Employee emp9 = new Employee("Tural", "tural@mail.com", 29, 4700);
Employee emp10 = new Employee("Gunel", "gunel@mail.com", 26, 3600);

try (FileWriter fw = new FileWriter("employee.txt", true);) {
fw.write("Name: " + emp1.getName() + " Email: " + emp1.getEmail() +
" Age: " + emp1.getAge() + " Salary: " + emp1.getSalary() + "\n");

fw.write("Name: " + emp2.getName() + " Email: " + emp2.getEmail() +
" Age: " + emp2.getAge() + " Salary: " + emp2.getSalary() + "\n");

fw.write("Name: " + emp3.getName() + " Email: " + emp3.getEmail() +
" Age: " + emp3.getAge() + " Salary: " + emp3.getSalary() + "\n");

fw.write("Name: " + emp4.getName() + " Email: " + emp4.getEmail() +
" Age: " + emp4.getAge() + " Salary: " + emp4.getSalary() + "\n");

fw.write("Name: " + emp5.getName() + " Email: " + emp5.getEmail() +
" Age: " + emp5.getAge() + " Salary: " + emp5.getSalary() + "\n");

fw.write("Name: " + emp6.getName() + " Email: " + emp6.getEmail() +
" Age: " + emp6.getAge() + " Salary: " + emp6.getSalary() + "\n");

fw.write("Name: " + emp7.getName() + " Email: " + emp7.getEmail() +
" Age: " + emp7.getAge() + " Salary: " + emp7.getSalary() + "\n");

fw.write("Name: " + emp8.getName() + " Email: " + emp8.getEmail() +
" Age: " + emp8.getAge() + " Salary: " + emp8.getSalary() + "\n");

fw.write("Name: " + emp9.getName() + " Email: " + emp9.getEmail() +
" Age: " + emp9.getAge() + " Salary: " + emp9.getSalary() + "\n");

fw.write("Name: " + emp10.getName() + " Email: " + emp10.getEmail() +
" Age: " + emp10.getAge() + " Salary: " + emp10.getSalary() + "\n");

}

String fileName = "employee.txt";
File loadFile = new File("employee.txt");
try (Scanner reader = new Scanner(loadFile)) {
while (reader.hasNextLine()) {
System.out.println(reader.nextLine());

}
}


}
}