Skip to content
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
27 changes: 27 additions & 0 deletions src/DifferenceBetweenArrays.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
60 changes: 60 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -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("--------------------");


}

}

28 changes: 28 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}




26 changes: 26 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}

}

}
39 changes: 39 additions & 0 deletions src/SmallestElement.java
Original file line number Diff line number Diff line change
@@ -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);


}
}