From 26a1aff8e8b9032b16131d2a2820ecdf36d763e9 Mon Sep 17 00:00:00 2001 From: danotoriousflaco101 Date: Fri, 28 Mar 2025 02:20:43 +0100 Subject: [PATCH 1/5] Lab001 --- .gitignore | 29 ++++++++++++++++ .idea/.gitignore | 3 ++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 4 +++ Lab001Completed.iml | 11 ++++++ src/Employee.java | 31 +++++++++++++++++ src/Intern.java | 17 +++++++++ src/Main.java | 84 +++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Lab001Completed.iml create mode 100644 src/Employee.java create mode 100644 src/Intern.java create mode 100644 src/Main.java 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..d843f34 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,4 @@ + + + + \ 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..5fb069b --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,31 @@ +class Employee { + private String name; + private int age; + private double salary; + + public Employee(String name, int age, double salary) { + this.name = name; + this.age = age; + this.salary = salary; + } + + public String getName() { + return this.name; + } + + public int getAge() { + return this.age; + } + + public double getSalary() { + return this.salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + 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..41e5c4a --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,17 @@ +class Intern extends Employee { + private static final double MAX_SALARY = (double)20000.0F; + + public Intern(String name, int age, double salary) { + super(name, age, salary); + this.setSalary(salary); + } + + public void setSalary(double salary) { + if (salary > (double)20000.0F) { + super.setSalary((double)20000.0F); + } else { + super.setSalary(salary); + } + + } +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..b32f4fc --- /dev/null +++ b/src/Main.java @@ -0,0 +1,84 @@ +import java.util.ArrayList; +import java.util.List; + +public class Main { + public Main() { + } + + public static void main(String[] args) { + System.out.println("Hired Staff Report + Salary details"); + System.out.println("-----------------------------------"); + List employees = new ArrayList(); + employees.add(new Employee("Marco", 35, (double)1900.0F)); + employees.add(new Employee("Alino", 15, (double)2000.0F)); + employees.add(new Employee("Giamma", 35, (double)1900.0F)); + employees.add(new Intern("Wade", 40, (double)5000.0F)); + employees.add(new Employee("Flo", 47, (double)5000.0F)); + employees.add(new Intern("Tony", 24, (double)1300.0F)); + employees.add(new Employee("Jons", 32, (double)1500.0F)); + employees.add(new Intern("Luca", 21, (double)1000.0F)); + employees.add(new Employee("Dani", 29, (double)1600.0F)); + employees.add(new Intern("Nico", 23, (double)1500.0F)); + + for(Employee employee : employees) { + System.out.println(employee); + } + + double salaryDifference = getSalaryDifference(employees); + System.out.println("Difference between highest and lowest salary is: " + salaryDifference); + findSmallestAndSecondSmallestSalary(employees); + System.out.println(); + 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."); + } + + public static double getSalaryDifference(List employees) { + double maxSalary = ((Employee)employees.get(0)).getSalary(); + double minSalary = ((Employee)employees.get(0)).getSalary(); + String maxSalaryName = ((Employee)employees.get(0)).getName(); + String minSalaryName = ((Employee)employees.get(0)).getName(); + + for(Employee employee : employees) { + if (employee.getSalary() > maxSalary) { + maxSalary = employee.getSalary(); + maxSalaryName = employee.getName(); + } + + if (employee.getSalary() < minSalary) { + minSalary = employee.getSalary(); + minSalaryName = employee.getName(); + } + } + + System.out.println("\nHighest salary paid is received by: " + maxSalaryName + ": " + maxSalary); + System.out.println("Lowest salary is received by: " + minSalaryName + ": " + minSalary); + return maxSalary - minSalary; + } + + public static void findSmallestAndSecondSmallestSalary(List employees) { + if (employees.size() < 1) { + System.out.println("Error, there must be at least 1 employees listed."); + } else { + double smallestSalary = Double.MAX_VALUE; + double secondSmallestSalary = Double.MAX_VALUE; + String smallestSalaryName = ""; + String secondSmallestSalaryName = ""; + + for(Employee employee : employees) { + double 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(); + } + } + + System.out.println("2nd lowest salary is paid to: " + secondSmallestSalaryName + ": " + secondSmallestSalary); + } + } +} \ No newline at end of file From 4ad42087a5511b70dfa2d9b8ebae20a077f4fea5 Mon Sep 17 00:00:00 2001 From: danotoriousflaco101 Date: Fri, 28 Mar 2025 03:04:42 +0100 Subject: [PATCH 2/5] Lab001 completed and revisited --- lab-java-basics-es | 1 + 1 file changed, 1 insertion(+) create mode 160000 lab-java-basics-es diff --git a/lab-java-basics-es b/lab-java-basics-es new file mode 160000 index 0000000..26b49a5 --- /dev/null +++ b/lab-java-basics-es @@ -0,0 +1 @@ +Subproject commit 26b49a57af109a88e9e57a1dbe22c533e8d3f124 From b16ff374a44502db5a7af665e66ee8bfe170aed4 Mon Sep 17 00:00:00 2001 From: danotoriousflaco101 Date: Fri, 28 Mar 2025 03:40:15 +0100 Subject: [PATCH 3/5] Lab001 final changes --- .idea/vcs.xml | 6 ++- lab-java-basics-es | 1 - src/Employee.java | 18 ++++++--- src/Intern.java | 17 ++++---- src/Main.java | 96 ++++++++++++++++++++++++++-------------------- 5 files changed, 80 insertions(+), 58 deletions(-) delete mode 160000 lab-java-basics-es diff --git a/.idea/vcs.xml b/.idea/vcs.xml index d843f34..cc50e15 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,4 +1,8 @@ - + + + + + \ No newline at end of file diff --git a/lab-java-basics-es b/lab-java-basics-es deleted file mode 160000 index 26b49a5..0000000 --- a/lab-java-basics-es +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 26b49a57af109a88e9e57a1dbe22c533e8d3f124 diff --git a/src/Employee.java b/src/Employee.java index 5fb069b..d267705 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -1,30 +1,36 @@ class Employee { - private String name; - private int age; - private double salary; + private String name; // Name of the employee + private int age; // Age of the employee + private int salary; // Salary of the employee - public Employee(String name, int age, double salary) { + // 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; } - public double getSalary() { + // Getter for the salary + public int getSalary() { return this.salary; } - public void setSalary(double 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; } diff --git a/src/Intern.java b/src/Intern.java index 41e5c4a..3e01a6d 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -1,17 +1,18 @@ class Intern extends Employee { - private static final double MAX_SALARY = (double)20000.0F; + private static final int MAX_SALARY = 20000; // Maximum salary for an intern - public Intern(String name, int age, double salary) { + // Constructor to initialize a new intern + public Intern(String name, int age, int salary) { super(name, age, salary); - this.setSalary(salary); + this.setSalary(salary); // Set the salary using the setter } - public void setSalary(double salary) { - if (salary > (double)20000.0F) { - super.setSalary((double)20000.0F); + // 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); + super.setSalary(salary); // If else will set the normal salary } - } } \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index b32f4fc..f9ddbe5 100644 --- a/src/Main.java +++ b/src/Main.java @@ -2,44 +2,51 @@ import java.util.List; public class Main { - public Main() { - } - public static void main(String[] args) { System.out.println("Hired Staff Report + Salary details"); System.out.println("-----------------------------------"); - List employees = new ArrayList(); - employees.add(new Employee("Marco", 35, (double)1900.0F)); - employees.add(new Employee("Alino", 15, (double)2000.0F)); - employees.add(new Employee("Giamma", 35, (double)1900.0F)); - employees.add(new Intern("Wade", 40, (double)5000.0F)); - employees.add(new Employee("Flo", 47, (double)5000.0F)); - employees.add(new Intern("Tony", 24, (double)1300.0F)); - employees.add(new Employee("Jons", 32, (double)1500.0F)); - employees.add(new Intern("Luca", 21, (double)1000.0F)); - employees.add(new Employee("Dani", 29, (double)1600.0F)); - employees.add(new Intern("Nico", 23, (double)1500.0F)); - for(Employee employee : employees) { + 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); } - double salaryDifference = getSalaryDifference(employees); + // 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."); } - public static double getSalaryDifference(List employees) { - double maxSalary = ((Employee)employees.get(0)).getSalary(); - double minSalary = ((Employee)employees.get(0)).getSalary(); - String maxSalaryName = ((Employee)employees.get(0)).getName(); - String minSalaryName = ((Employee)employees.get(0)).getName(); + // 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(); - for(Employee employee : employees) { + // 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(); @@ -51,34 +58,39 @@ public static double getSalaryDifference(List employees) { } } + // 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 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 employees listed."); - } else { - double smallestSalary = Double.MAX_VALUE; - double secondSmallestSalary = Double.MAX_VALUE; - String smallestSalaryName = ""; - String secondSmallestSalaryName = ""; + System.out.println("Error, there must be at least 1 employee listed."); + return; + } - for(Employee employee : employees) { - double 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(); - } - } + int smallestSalary = Integer.MAX_VALUE; + int secondSmallestSalary = Integer.MAX_VALUE; + String smallestSalaryName = ""; + String secondSmallestSalaryName = ""; - System.out.println("2nd lowest salary is paid to: " + secondSmallestSalaryName + ": " + secondSmallestSalary); + // 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 From bcd9fe8f427c2a46dcff484e66867c3144cc15c7 Mon Sep 17 00:00:00 2001 From: danotoriousflaco101 Date: Fri, 28 Mar 2025 04:12:19 +0100 Subject: [PATCH 4/5] Lab001 --- src/Intern.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Intern.java b/src/Intern.java index 3e01a6d..a0d16ef 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -12,7 +12,7 @@ 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 else will set the normal salary + super.setSalary(salary); // If not, it will set the normal salary } } } \ No newline at end of file From f419ec0185958ffb9b9dfa90f9f4ebe8155bee40 Mon Sep 17 00:00:00 2001 From: danotoriousflaco101 Date: Fri, 28 Mar 2025 04:14:48 +0100 Subject: [PATCH 5/5] Lab001 finally all done and working with git --- src/Employee.java | 2 +- src/Intern.java | 2 +- src/Main.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Employee.java b/src/Employee.java index d267705..598a2b8 100644 --- a/src/Employee.java +++ b/src/Employee.java @@ -30,7 +30,7 @@ public void setSalary(int salary) { this.salary = salary; } - // Override of the toString method to print employee with details + // Override of the toString method to print employee with details! public String toString() { return "Employee name= " + this.name + ", age= " + this.age + ", salary= " + this.salary; } diff --git a/src/Intern.java b/src/Intern.java index a0d16ef..a9d8be4 100644 --- a/src/Intern.java +++ b/src/Intern.java @@ -12,7 +12,7 @@ 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 + 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 index f9ddbe5..1de086b 100644 --- a/src/Main.java +++ b/src/Main.java @@ -19,7 +19,7 @@ public static void main(String[] args) { employees.add(new Employee("Dani", 29, 1600)); employees.add(new Intern("Nico", 23, 1500)); - // Printing details of all employees + // Printing details of all employees! for (Employee employee : employees) { System.out.println(employee); }