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
67 changes: 67 additions & 0 deletions src/main/java/org/example/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.example;

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){
setName(name);
setEmail(email);
setAge(age);
setSalary(salary);
}

public String getName() {
return name;
}

public void setName(String name) {
if (name == null) {
System.out.println("Name is null");
return;
}
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
if (email == null || !email.contains("@")) {
System.out.println("Email is null");
return;
}
this.email = email;
}

public int getAge() {
return age;
}

public void setAge(int age) {
if (age > 0) {
this.age = age;
} else {
System.out.println("Age must be positive.");
}
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
if (salary >= 0) {
this.salary = salary;
} else {
System.out.println("Salary cannot be negative.");
}
}

public String getDetails(){
return "Name: " + name + ", Email: " + email + ", Age: " + age + ", Salary: " + salary;
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/example/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.example;

public class Intern extends Employee {
private static final double maxSalary = 20000;
public Intern(String name, String email, int age, double salary) {
super(name, email, age, salary);
}
@Override
public void setSalary(double salary) {
if (salary > maxSalary) {
System.out.println("Salary is greater than max salary");
}else {
super.setSalary(salary);
}
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.example;

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

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
Employee[] employees = new Employee[10];

employees[0] = new Employee("John Smith", "john.smith@mail.com", 30, 5000);
employees[1] = new Employee("Emma Johnson", "emma.johnson@mail.com", 28, 6200);
employees[2] = new Employee("Michael Brown", "michael.brown@mail.com", 35, 7200);
employees[3] = new Employee("Olivia Davis", "olivia.davis@mail.com", 26, 4800);
employees[4] = new Employee("William Miller", "william.miller@mail.com", 40, 8500);
employees[5] = new Employee("Sophia Wilson", "sophia.wilson@mail.com", 32, 6900);
employees[6] = new Employee("James Moore", "james.moore@mail.com", 29, 5400);
employees[7] = new Employee("Isabella Taylor", "isabella.taylor@mail.com", 27, 5100);
employees[8] = new Employee("Benjamin Anderson", "ben.anderson@mail.com", 38, 9100);
employees[9] = new Employee("Mia Thomas", "mia.thomas@mail.com", 31, 6300);

try(FileWriter fw = new FileWriter("employee.txt")){
for(Employee emp : employees){
fw.write(emp.getDetails() + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}