Skip to content

;) Lab done, i hope now git works well too #8

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 5 commits 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
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 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.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Lab001Completed.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
37 changes: 37 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 18 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -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!
}
}
}
96 changes: 96 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -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<Employee> 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<Employee> 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<Employee> 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);
}
}