diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/lab-java-standard-input-and-classes.iml b/.idea/lab-java-standard-input-and-classes.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/.idea/lab-java-standard-input-and-classes.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..69ace3f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..398d0f7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/lab-java-standard-input-and-classes/Employee.class b/out/production/lab-java-standard-input-and-classes/Employee.class new file mode 100644 index 0000000..0315e12 Binary files /dev/null and b/out/production/lab-java-standard-input-and-classes/Employee.class differ diff --git a/out/production/lab-java-standard-input-and-classes/Intern.class b/out/production/lab-java-standard-input-and-classes/Intern.class new file mode 100644 index 0000000..c0a16d3 Binary files /dev/null and b/out/production/lab-java-standard-input-and-classes/Intern.class differ diff --git a/out/production/lab-java-standard-input-and-classes/main.class b/out/production/lab-java-standard-input-and-classes/main.class new file mode 100644 index 0000000..703ed25 Binary files /dev/null and b/out/production/lab-java-standard-input-and-classes/main.class differ diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..993b222 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,52 @@ +public class Employee { + private String name; + private String email; + private int age; + protected double salary; + + // Constructors + + public Employee() { + + } + + public Employee(String name, String email, int age, double salary) { + setName(name); + setEmail(email); + setAge(age); + setSalary(salary); + } + + + //Setters + public void setName(String name) { + this.name = name; + } + public void setEmail(String email) { + if (email.contains("@")) { + this.email = email; + } else { + this.email = "The email must be valid"; + } + } + public void setAge(int age) { + this.age = age; + } + public void setSalary(double salary) { + this.salary = salary; + } + //Getters + public String getName() { + return this.name; + } + public String getEmail() { + return this.email; + } + public int getAge() { + return this.age; + } + public double getSalary() { + return this.salary; + } + +} diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..2d5721e --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,22 @@ +class Intern extends Employee { + private static final double MAX_SALARY = 20000; + + //Constructor + public Intern(String name, String email, int age, double salary) { + super.setName(name); + super.setEmail(email); + super.setAge(age); + if (salary <= MAX_SALARY) { + super.setSalary(salary); + } else { + double newSalary = Math.min(salary, MAX_SALARY); + setSalary(newSalary); + } + } + + + + + + +} diff --git a/src/main.java b/src/main.java new file mode 100644 index 0000000..5a4e4b9 --- /dev/null +++ b/src/main.java @@ -0,0 +1,37 @@ +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; + +public class main { + public static void main(String[] args) { + + Employee[] employees = new Employee[5]; + employees[0] = new Employee("John", "john@example.com", 30, 50000.0); + employees[1] = new Employee("Alice", "alice@example.com", 28, 48000.0); + employees[2] = new Intern("Adan", "adan@example.com", 20, 48000.0); + employees[3] = new Intern("John", "fskdj@fklsdjf", 25, 1800 ); + employees[4] = new Employee("Carlos", "fskdjfklsdjf", 25, 566666); + + + for (Employee employee : employees) { + System.out.println("Name: " + employee.getName() + " Email: " + employee.getEmail() + " Age: " + employee.getAge() + " Salary: " + employee.getSalary() + "€"); + System.out.println("-----------------------------------------"); + } + + + String filename = "employees.txt"; + try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) { + for (Employee employee : employees) { + String info = "Name: " + employee.getName() + ", Email: " + employee.getEmail() + ", Age: " + + employee.getAge() + ", Salary: " + employee.getSalary(); + writer.write(info + "\n"); + } + System.out.println("Employees' information has been written to " + filename); + } catch (IOException e) { + System.out.println("An error occurred while writing to the file: " + e.getMessage()); + } + + + } +}