Skip to content

first push #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
32 changes: 32 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 String getEmail() {
return email;
}

public int getAge() {
return age;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}
}
17 changes: 17 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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);
setSalary(salary);
}

@Override
public void setSalary(double salary) {
if (salary > MAX_SALARY) {
throw new IllegalArgumentException("El salario máximo para un becario es de " + MAX_SALARY + "€");
} else {
super.setSalary(salary);
}
}
}
27 changes: 27 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
Employee[] employees = {
new Employee("John", "[email protected]", 25, 50000),
new Employee("Jane", "[email protected]", 28, 60000),
new Employee("Bob", "[email protected]", 22, 55000),
new Employee("Alice", "[email protected]", 30, 70000),
new Employee("Charlie", "[email protected]", 24, 48000),
new Intern("Eva", "[email protected]", 26, 15000),
new Intern("David", "[email protected]", 29, 20000),
new Intern("Grace", "[email protected]", 23, 12000),
new Intern("Frank", "[email protected]", 27, 16000),
new Intern("Helen", "[email protected]", 31, 19000)
};
FileWriter writer = new FileWriter("employees.txt", true);
for (Employee employee : employees) {
writer.write("Name: " + employee.getName() + "\n");
writer.write("Email: " + employee.getEmail() + "\n");
writer.write("Age: " + employee.getAge() + "\n");
writer.write("Salary: " + employee.getSalary() + "\n");
writer.write("\n");
}
writer.close();
}
}