diff --git a/src/DifferenceBetweenArrays.java b/src/DifferenceBetweenArrays.java new file mode 100644 index 0000000..aa2b5c0 --- /dev/null +++ b/src/DifferenceBetweenArrays.java @@ -0,0 +1,27 @@ +public class DifferenceBetweenArrays { + public static int getDifference(int[] arr) { + + int max = arr[0]; + int min = arr[0]; + + + for (int i = 1; i < arr.length; i++) { + if (arr[i] > max) { + max = arr[i]; + } + if (arr[i] < min) { + min = arr[i]; + } + } + + return max - min; + } + + public static void main(String[] args) { + + int[] numbers = {3, 7, 2, 9, 5, 10}; + + int difference = getDifference(numbers); + System.out.println("The Difference between the largest and the smallest value is " + difference); + } +} \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..a794fe4 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,60 @@ +public class Employee { + + private String name; + private String position; + private double salary; + + public Employee(String name, String position, double salary) { + this.name = name; + this.position = position; + this.salary = salary; + + } + + public static void add(Employee employee) { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public double getSalary() { + return salary; + } + + public void setSalary(double salary) { + this.salary = salary; + } + + @Override + public String toString() { + return "Employee{" + + "name='" + name + '\'' + + ", position='" + position + '\'' + + ", salary=" + salary + + '}'; + } + + public void displayDetails() { + System.out.println("Name: " + name); + System.out.println("Position: " + position); + System.out.println("Salary: " + salary); + System.out.println("--------------------"); + + + } + +} + diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..7c60569 --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,28 @@ +public class Intern extends Employee { + public static final double MAX_SALARY = 20000; + + + public Intern(String name, String position, double salary) { + super(name, position, checkSalary(salary)); + } + + private static double checkSalary(double salary) { + if (salary > MAX_SALARY) { + System.out.println("Salary exceeds the limit for Interns " + MAX_SALARY); + return MAX_SALARY; + } + return salary; + } + + public void setSalary(double salary) { + if (salary > MAX_SALARY) { + System.out.println("Intern salary cannot exceed " + MAX_SALARY); + } else { + super.setSalary(salary); + } + } +} + + + + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..be870e6 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,26 @@ +import java.util.ArrayList; + +public class Main { + public static void main(String[] args) { + + Employee[] employees = { + + new Intern("Salavatore", "Senior Sofware Dev", 30000), + new Employee("Elodie", "HR", 20000), + new Employee("David", "Junior Sofware Dev", 15000), + new Employee("Tosin", "Sofware Dev", 18000), + new Employee("Colin", "Junior Sofware Dev", 15000), + new Employee("Rosca", "It", 19000), + new Employee("Ahmad", "Web Dev", 16000), + new Employee("Tino", "Web Dev", 16000), + new Employee("Kasia", "Senior Web Dev", 19000), + new Employee("Cesar", "Senior Web Dev", 18000) + }; + + for (Employee emp : employees) { + emp.displayDetails(); + } + + } + +} \ No newline at end of file diff --git a/src/SmallestElement.java b/src/SmallestElement.java new file mode 100644 index 0000000..e8a8ed2 --- /dev/null +++ b/src/SmallestElement.java @@ -0,0 +1,39 @@ +public class SmallestElement { + public static void findSmallestAndSecondSmallest(int[] arr) { + + if (arr.length < 2) { + System.out.println("You must have two elements"); + return; + } + + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MIN_VALUE; + + for (int num : arr) { + if (num < smallest) { + secondSmallest = smallest; + smallest = num; + } else if (num < secondSmallest && num != smallest) { + secondSmallest = num; + + } + + if (secondSmallest == Integer.MAX_VALUE) { + } else { + System.out.println("Smallest: " + smallest); + System.out.println("Second Smallest: " + secondSmallest); + + } + } + } + + public static void main(String[] args) { + int[] numbers = {3, 7, 2, 9, 5, 10}; + + findSmallestAndSecondSmallest(numbers); + + + } +} + +