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
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
.kotlin

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions .idea/.gitignore

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.

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.

50 changes: 50 additions & 0 deletions employees.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Name: Robert King
Email: [email protected]
Age: 34
Salary: 27000.00
================
Name: Laura Scott
Email: [email protected]
Age: 29
Salary: 21000.00
================
Name: Kevin Turner
Email: [email protected]
Age: 41
Salary: 32000.00
================
Name: Natalie Adams
Email: [email protected]
Age: 26
Salary: 17000.00
================
Name: Brian Nelson
Email: [email protected]
Age: 38
Salary: 29000.00
================
Name: Samantha Carter
Email: [email protected]
Age: 30
Salary: 24000.00
================
Name: Andrew Mitchell
Email: [email protected]
Age: 45
Salary: 35000.00
================
Name: Rachel Perez
Email: [email protected]
Age: 23
Salary: 90000.00
================
Name: Max Safarli
Email: [email protected]
Age: 22
Salary: 2100.00
================
Name: Ali Safarli
Email: [email protected]
Age: 20
Salary: 0.00
================
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions 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>com.ironhack</groupId>
<artifactId>java-standart-input-and-classes</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>
62 changes: 62 additions & 0 deletions src/main/java/com/ironhack/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.ironhack;

public class Employee {
private String name;
private int age;
private String email;
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 != null) {
this.name = name;
}else {
System.err.println("Employee name cannot be null");
}
}

public int getAge() {
return age;
}

public void setAge(int age) {
if (age >0) {
this.age = age;

}else {
System.err.println("Age must be greater than 0");
}
}

public String getEmail() {
return email;
}

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

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
if (salary > 0) {
this.salary = salary;
}else {
System.err.println("Salary cannot be negative");
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/ironhack/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ironhack;

public class Intern extends Employee {

private static final double SALARY_LIMIT=20000;

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

@Override
public void setSalary(double salary) {
if(salary>SALARY_LIMIT){
System.err.println("Salary must be maximum 20000.0: "+salary);
return;
}

super.setSalary(salary);
}
}
54 changes: 54 additions & 0 deletions src/main/java/com/ironhack/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.ironhack;

import java.io.FileWriter;
import java.io.IOException;


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

employees[0] = new Employee("Robert King", "[email protected]", 34, 27000);
employees[1] = new Employee("Laura Scott", "[email protected]", 29, 21000);
employees[2] = new Employee("Kevin Turner", "[email protected]", 41, 32000);
employees[3] = new Employee("Natalie Adams", "[email protected]", 26, 17000);
employees[4] = new Employee("Brian Nelson", "[email protected]", 38, 29000);
employees[5] = new Employee("Samantha Carter", "[email protected]", 30, 24000);
employees[6] = new Employee("Andrew Mitchell", "[email protected]", 45, 35000);
employees[7] = new Employee("Rachel Perez", "[email protected]", 23, 90000);
employees[8]=new Intern("Max Safarli","[email protected]",22,2100);
employees[9]=new Intern("Ali Safarli","[email protected]",20,22000);




makeEmployeesFile(employees);

}

public static String getDetailsEmployess(Employee employee) {
return String.format("""
Name: %s
Email: %s
Age: %d
Salary: %.2f
================
""", employee.getName(), employee.getEmail(), employee.getAge(), employee.getSalary());
}

public static void makeEmployeesFile(Employee[]employees){
String fileName = "employees.txt";

try(FileWriter writer = new FileWriter(fileName)) {
for (Employee employee : employees) {
String content = getDetailsEmployess(employee);

writer.write(content);
}
System.out.println("New file created successfully.");
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
}
}

}