diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..47478b9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fbc0a2b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..cc50e15 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lab001Completed.iml b/Lab001Completed.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab001Completed.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..598a2b8 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,37 @@ +class Employee { + private String name; // Name of the employee + private int age; // Age of the employee + private int salary; // Salary of the employee + + // Constructor to initialize a new employee + public Employee(String name, int age, int salary) { + this.name = name; + this.age = age; + this.salary = salary; + } + + // Getter for the name + public String getName() { + return this.name; + } + + // Getter for the age + public int getAge() { + return this.age; + } + + // Getter for the salary + public int getSalary() { + return this.salary; + } + + // Setter for the salary + public void setSalary(int salary) { + this.salary = salary; + } + + // Override of the toString method to print employee with details! + public String toString() { + return "Employee name= " + this.name + ", age= " + this.age + ", salary= " + this.salary; + } +} \ No newline at end of file diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..a9d8be4 --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,18 @@ +class Intern extends Employee { + private static final int MAX_SALARY = 20000; // Maximum salary for an intern + + // Constructor to initialize a new intern + public Intern(String name, int age, int salary) { + super(name, age, salary); + this.setSalary(salary); // Set the salary using the setter + } + + // Setter for the salary, with a check for the maximum salary + public void setSalary(int salary) { + if (salary > MAX_SALARY) { + super.setSalary(MAX_SALARY); // Set to maximum salary if it exceeds the limit + } else { + super.setSalary(salary); // If not, it will set the normal salary! + } + } +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..1de086b --- /dev/null +++ b/src/Main.java @@ -0,0 +1,96 @@ +import java.util.ArrayList; +import java.util.List; + +public class Main { + public static void main(String[] args) { + System.out.println("Hired Staff Report + Salary details"); + System.out.println("-----------------------------------"); + + List employees = new ArrayList<>(); + // Adding employees and interns to the list + employees.add(new Employee("Marco", 35, 1900)); + employees.add(new Employee("Alino", 15, 2000)); + employees.add(new Employee("Giamma", 35, 1900)); + employees.add(new Intern("Wade", 40, 5000)); + employees.add(new Employee("Flo", 47, 5000)); + employees.add(new Intern("Tony", 24, 1300)); + employees.add(new Employee("Jons", 32, 1500)); + employees.add(new Intern("Luca", 21, 1000)); + employees.add(new Employee("Dani", 29, 1600)); + employees.add(new Intern("Nico", 23, 1500)); + + // Printing details of all employees! + for (Employee employee : employees) { + System.out.println(employee); + } + + // Calculate and print the difference between the highest and lowest salary + int salaryDifference = getSalaryDifference(employees); + System.out.println("Difference between highest and lowest salary is: " + salaryDifference); + + // Find and print the second lowest salary + findSmallestAndSecondSmallestSalary(employees); + System.out.println(); + + // Final message + System.out.println("---> Flaco Workload Management System brought to you by FlacoCorp Economy Division \ud83e\udd86 <---"); + System.out.println("\"Ask not what your country can do for you – ask how many taxes you do owe to your country.\""); + System.out.println("John Quackgerald Kennedy, 2025."); + } + + // Method to calculate the difference between the highest and lowest salary + public static int getSalaryDifference(List employees) { + int maxSalary = employees.get(0).getSalary(); + int minSalary = employees.get(0).getSalary(); + String maxSalaryName = employees.get(0).getName(); + String minSalaryName = employees.get(0).getName(); + + // Iterate through the list of employees to find the maximum and minimum salary + for (Employee employee : employees) { + if (employee.getSalary() > maxSalary) { + maxSalary = employee.getSalary(); + maxSalaryName = employee.getName(); + } + + if (employee.getSalary() < minSalary) { + minSalary = employee.getSalary(); + minSalaryName = employee.getName(); + } + } + + // Print the results + System.out.println("\nHighest salary paid is received by: " + maxSalaryName + ": " + maxSalary); + System.out.println("Lowest salary is received by: " + minSalaryName + ": " + minSalary); + return maxSalary - minSalary; // Return the difference + } + + // Method to find the second smallest salary + public static void findSmallestAndSecondSmallestSalary(List employees) { + if (employees.size() < 1) { + System.out.println("Error, there must be at least 1 employee listed."); + return; + } + + int smallestSalary = Integer.MAX_VALUE; + int secondSmallestSalary = Integer.MAX_VALUE; + String smallestSalaryName = ""; + String secondSmallestSalaryName = ""; + + // Loop through the list of employees to find the smallest and second smallest salary + for (Employee employee : employees) { + int salary = employee.getSalary(); + if (salary < smallestSalary) { + secondSmallestSalary = smallestSalary; + secondSmallestSalaryName = smallestSalaryName; + smallestSalary = salary; + smallestSalaryName = employee.getName(); + } else if (salary < secondSmallestSalary && salary != smallestSalary) { + secondSmallestSalary = salary; + secondSmallestSalaryName = employee.getName(); + } + } + + // Print the second smallest salary + System.out.println("2nd lowest salary is paid to: " + secondSmallestSalaryName + ": " + secondSmallestSalary); + } +} \ No newline at end of file