Skip to content

Standard Input and Classes Lab. #20

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 1 commit 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
51 changes: 51 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 "Employee{name='" + name + "', email='" + email + "', age=" + age + ", salary=" + salary + '}';
}
}

19 changes: 19 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Intern extends Employee {
private static final double SALARY_LIMIT = 20000.0;

public Intern(String name, String email, int age, double salary) {
super(name, email, age, salary);
if (salary > SALARY_LIMIT) {
throw new IllegalArgumentException("Salary exceeds the limit for interns");
}
}

@Override
public void setSalary(double salary) {
if (salary > SALARY_LIMIT) {
throw new IllegalArgumentException("Salary exceeds the limit for interns");
}
super.setSalary(salary);
}
}

33 changes: 33 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

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

// Create Employee objects
employees.add(new Employee("Goldylocks", "[email protected]", 30, 50000));
employees.add(new Employee("PapaBear", "[email protected]", 25, 45000));
employees.add(new Employee("MamaBear", "[email protected]", 28, 48000));
employees.add(new Employee("BabyBear", "[email protected]", 35, 52000));
employees.add(new Employee("Leonardo", "[email protected]", 22, 43000));
employees.add(new Employee("Michelangelo", "[email protected]", 31, 47000));
employees.add(new Employee("Raphael", "[email protected]", 27, 46000));
employees.add(new Employee("Donatello", "[email protected]", 29, 49000));
employees.add(new Employee("Jack", "[email protected]", 26, 44000));
employees.add(new Employee("Jill", "[email protected]", 32, 51000));

// Write employee information to a file
try (PrintWriter writer = new PrintWriter(new FileWriter("employees.txt"))) {
for (Employee employee : employees) {
writer.println(employee);
}
} catch (IOException e) {
System.out.println("An error occurred while writing to the file: " + e.getMessage());
}
}
}