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
49 changes: 49 additions & 0 deletions lab-1/src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
public class Employee {
private String name;
private int id;
private String department;
private double salary;
private boolean isEmployed;

public Employee(String name, int id, String department, double salary, boolean isEmployed) {
this.name = name;
this.id = id;
this.department = department;
this.salary = salary;
this.isEmployed = isEmployed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public Boolean isEmployed() {
return isEmployed;
}
public void setEmployed (boolean employed) {
this.isEmployed = employed;
}
public String toString() {
return "Employee [ID=" + id + ", Name=" + name + ", Department=" + department
+ ", Salary=" + salary + ", Employed=" + isEmployed + "]";
}
}
30 changes: 30 additions & 0 deletions lab-1/src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Intern extends Employee {
private static final double MAX_SALARY = 20000;

public Intern(String name, int id, String department, double salary, boolean isEmployed) {
super(name, id, department, validateSalary(salary), isEmployed);
super.setEmployed(isEmployed);
}
public Intern(String name, int id, String department, double salary) {
this(name, id, department, salary, true);
}
private static double validateSalary(double salary) {
if (salary > MAX_SALARY) {
System.out.println("Salary exceeds the limit for an Intern. Setting to " + MAX_SALARY);
return MAX_SALARY;
}
return salary;
}
public void setSalary(double salary) {
if (salary > MAX_SALARY) {
System.out.println("Salary exceeds limit for an Intern. Setting to within " + MAX_SALARY);
super.setSalary(MAX_SALARY);
} else {
super.setSalary(salary);
}
}
public String toString() {
return "Intern [ID=" + getId() + ", Name=" + getName() + ", Department=" + getDepartment()
+ ", Salary=" + getSalary() + ", Employed=" + isEmployed() + "]";
}
}
22 changes: 22 additions & 0 deletions lab-1/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
Employee[] employees_list = new Employee[10];

employees_list[0] = new Employee("Vanessa", 1, "HR", 50000, true);
employees_list[1] = new Employee("Vanessa_2", 2, "HR", 70000, true);
employees_list[2] = new Employee("Vanessa_3", 3, "HR", 45000, true);
employees_list[3] = new Employee("Vanessa_4", 4, "HR", 52000, true);
employees_list[4] = new Employee("Vanessa_5", 5, "HR", 50000, true);
employees_list[5] = new Employee("Vanessa_6", 6, "HR", 50000, true);
employees_list[6] = new Employee("Vanessa_7", 7, "HR", 50000, false);
employees_list[7] = new Employee("Vanessa_8", 8, "HR", 50000, false);
employees_list[8] = new Intern("Vanessa_9", 9, "HR", 21000, true);
employees_list[9] = new Intern("Audrey", 10, "HR", 15000, true);

for (Employee emp : employees_list) {
System.out.println(emp);
}
}
}
23 changes: 23 additions & 0 deletions lab-1/src/arrayDiff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class arrayDiff {

public static int getDiff (int[] nums) {
int minimum = nums[0];
int maximum = nums[0];

for (int i = 1; i < nums.length; i++) {
if (nums[i] < minimum) {
minimum = nums[i];
} else if (nums[i] > maximum) {
maximum = nums[i];
}
}

return maximum - minimum;
}

public static void main(String[] args) {
int[] numbers = {-3, -2, -2, -1, 0, 1, 2, 3, 3, 4};
int difference = getDiff(numbers);
System.out.println("The difference between the largest and smallest integer in the array is: " +difference);
}
}
31 changes: 31 additions & 0 deletions lab-1/src/twoSmallest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class twoSmallest {

public static void findTwoSmallest(int[] nums) {
int smallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;

for (int i = 0; i < nums.length; i++) {
int current = nums[i];

if (current < smallest) {
secondSmallest = smallest;
smallest = current;
} else if (current < secondSmallest && current != smallest) {
secondSmallest = current;
}
}
if (secondSmallest == Integer.MAX_VALUE) {
System.out.println("Array does not have a second smallest element");
} else {
System.out.println("Smallest: " + smallest);
System.out.println("Second Smallest: "+ secondSmallest);
}
}

public static void main(String[] args) {
int[] numbers = {-3, -2, -2, -1, 0, 1, 2, 3, 3, 4};
int[] numbers_2 = {1, 2, 3, 4, 5};
findTwoSmallest(numbers);
findTwoSmallest(numbers_2);
}
}