Skip to content
Open
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.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

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

7 changes: 7 additions & 0 deletions .idea/encodings.xml

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

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

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

9 changes: 9 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.

14 changes: 14 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.

17 changes: 17 additions & 0 deletions Lab2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.ironhack.envsetup</groupId>
<artifactId>Lab2</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
31 changes: 31 additions & 0 deletions Lab2/src/main/java/org/ironhack/envsetup/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.ironhack.envsetup;
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) { this.name = name; }

public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }

public int getAge() { return age; }
public void setAge(int age) { this.age = age; }

public double getSalary() { return salary; }
public void setSalary(double salary) { this.salary = salary; }

@Override
public String toString() {
return name + ", " + email + ", " + age + ", " + salary;
}
}
21 changes: 21 additions & 0 deletions Lab2/src/main/java/org/ironhack/envsetup/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.ironhack.envsetup;
public class Intern extends Employee {
public static final double SALARY_LIMIT = 20000;

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

private static double validateSalary(double salary) {
if (salary > SALARY_LIMIT) {
System.out.println("Salary exceeds intern limit. Setting to " + SALARY_LIMIT);
return SALARY_LIMIT;
}
return salary;
}

@Override
public void setSalary(double salary) {
super.setSalary(validateSalary(salary));
}
}
32 changes: 32 additions & 0 deletions Lab2/src/main/java/org/ironhack/envsetup/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.ironhack.envsetup;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class Main {
public static void main(String[] args) {
ArrayList<Employee> employees = new ArrayList<>();

employees.add(new Employee("Alice", "alice@email.com", 30, 50000));
employees.add(new Employee("Bob", "bob@email.com", 28, 48000));
employees.add(new Intern("Charlie", "charlie@email.com", 22, 25000));
employees.add(new Intern("Daisy", "daisy@email.com", 21, 18000));
employees.add(new Employee("Elena", "elena@email.com", 27, 47000));
employees.add(new Employee("Frank", "frank@email.com", 35, 52000));
employees.add(new Intern("George", "george@email.com", 23, 19000));
employees.add(new Intern("Hannah", "hannah@email.com", 21, 22000));
employees.add(new Employee("Ian", "ian@email.com", 40, 60000));
employees.add(new Employee("Jane", "jane@email.com", 29, 48000));


try (PrintWriter writer = new PrintWriter(new FileWriter("employees.txt"))) {
for (Employee emp : employees) {
writer.println(emp);
}
System.out.println("Employees written to employees.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions employees.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Alice, alice@email.com, 30, 50000.0
Bob, bob@email.com, 28, 48000.0
Charlie, charlie@email.com, 22, 20000.0
Daisy, daisy@email.com, 21, 18000.0