From 05cb8e01b8d18458a41122a018ba37dfb25cef42 Mon Sep 17 00:00:00 2001 From: Anikybee Date: Wed, 3 Sep 2025 21:14:57 +0200 Subject: [PATCH] Finished lab solution --- .idea/.gitignore | 3 ++ .idea/lab-java-basics.iml | 9 +++++ .idea/misc.xml | 6 +++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ src/Elements.java | 27 +++++++++++++ src/Employee.java | 85 +++++++++++++++++++++++++++++++++++++++ src/Integers.java | 33 +++++++++++++++ src/Intern.java | 26 ++++++++++++ src/Main.java | 67 ++++++++++++++++++++++++++++++ 10 files changed, 270 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/lab-java-basics.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 src/Elements.java create mode 100644 src/Employee.java create mode 100644 src/Integers.java create mode 100644 src/Intern.java create mode 100644 src/Main.java 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/lab-java-basics.iml b/.idea/lab-java-basics.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a9182a4 --- /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..505d07d --- /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..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Elements.java b/src/Elements.java new file mode 100644 index 0000000..f171720 --- /dev/null +++ b/src/Elements.java @@ -0,0 +1,27 @@ +public class Elements { + public static void main(String[] args) { + //Write a method in Java to find the + // smallest and second, smallest elements + // of a given array and print it in the + // console. Use loops and conditionals to + // develop the algorithm. + + String[] elements = new String[4]; + elements[0] = "3kg of Rice"; + elements[1] = "20kg of Maize"; + elements[2] = "25kg of Grains"; + elements[3] = "5kg of Flour"; + + System.out.println("Elements of the Array:"); + for (String element : elements) {System.out.println(element);} + + for (int i = 0; i < 1; i++) { + System.out.println(elements[i] + " is the smallest element:"); + } + + for (int i = 3; i < 4; i++) { + System.out.println(elements[i] + " is the second smallest element: "); + } + + } +} \ No newline at end of file diff --git a/src/Employee.java b/src/Employee.java new file mode 100644 index 0000000..84ae011 --- /dev/null +++ b/src/Employee.java @@ -0,0 +1,85 @@ +//Create an Employee class to represent +// an employee of a company. Add all relevant +// properties and behaviors that you might need +// but, you have to include a salary property. +// Don't forget to add getters and setters. + +public class Employee { + private String name; + private String department; + private String position; + private int salary; + private boolean workingEveryday; + + + public Employee (String name, String department, String position, int salary, boolean workingEveryday){ + this.name = (name); + this.department = (department); + this.position = (position); + this.salary = (salary); + this.workingEveryday = (true); + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDepartment(){ + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public int getSalary() { + return salary; + } + + public void setSalary(int salary) { + this.salary = salary; + } + + public boolean getWorkingEveryday() { + return workingEveryday; + } + + public void setWorkingEveryday(boolean isWorkingEveryday) { + this.workingEveryday = true; + } + + public void displayEmployeeInfo() { + System.out.println("Employee Details:"); + System.out.println("Name: " + name); + System.out.println("Department: " + department); + System.out.println("Position: " + position); + System.out.println("Salary: $" + salary); + System.out.println("Works Everyday: " + true); + } + + public void displayInternInfo() { + System.out.println("Employee Details:"); + System.out.println("Name: " + name); + System.out.println("Department: " + department); + System.out.println("Position: " + position); + System.out.println("Salary: $" + salary); + System.out.println("Works Everyday: " + true); + } + + + +} + diff --git a/src/Integers.java b/src/Integers.java new file mode 100644 index 0000000..6b4cc61 --- /dev/null +++ b/src/Integers.java @@ -0,0 +1,33 @@ + +public class Integers { + public static void main(String[] args) { + + //Write a method in Java to get the difference + // between the largest and smallest values in an + // array of integers. The length of the array must + // be 1 and above. Use loops and conditionals to + // develop the algorithm. + + int[] numberLists = {10, 20, 30, 40, 50, 60}; + int highestNumber = numberLists[0]; + for(int number : numberLists){ + if(number > highestNumber){ + highestNumber = number; + } + } + System.out.println("The Highest Number " + highestNumber); + + int lowestNumber = numberLists[0]; + for(int number : numberLists){ + if(number == lowestNumber){ + System.out.println("The Lowest Number " + lowestNumber); + } + } + + + int subtraction = highestNumber - lowestNumber; + System.out.println("The difference between Highest and Lowest Number is " + subtraction); + + } +} + diff --git a/src/Intern.java b/src/Intern.java new file mode 100644 index 0000000..a2cf5b4 --- /dev/null +++ b/src/Intern.java @@ -0,0 +1,26 @@ +public class Intern extends Employee { + + // Create an Intern class that extends + // from Employee. All the Interns have + // a salary limit of 20000 (constant). + // You must validate if an intern is + // created (or salary updated) with + // a bigger salary than the max. + // The max value is set. + + public static final int MAX_SALARY = 20000; + + public Intern(String name, String department, String position, int salary, boolean workingEveryday) { + super(name, department, position, Math.min(salary, MAX_SALARY), workingEveryday); + } + + public void setSalary(int salary) { + if (salary > MAX_SALARY) { + System.out.println("Salary exceeded max intern limit of $" + MAX_SALARY); + } else { + super.setSalary(salary); // Call superclass method if valid + } + } + + +} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..731d2fa --- /dev/null +++ b/src/Main.java @@ -0,0 +1,67 @@ +class Main { + public static void main(String[] args) { + + Employee employee1 = new Employee("Noah", "Quality Assurance", + " Controller", 35000, true); + employee1.displayEmployeeInfo(); + + Employee employee2 = new Employee("Cole", "IT", + " Cloud Engineer", 20000, true); + employee2.displayEmployeeInfo(); + + Employee employee3 = new Employee("Tola", "Operations", + " Manager", 30000, true); + employee3.displayEmployeeInfo(); + + Employee employee4 = new Employee("Bukunmi", "Problem Solve", + " Associate", 22000, true); + employee4.displayEmployeeInfo(); + + Employee employee5 = new Employee("Funmilola", "Receiving", + " Associate", 28000, true); + employee5.displayEmployeeInfo(); + + Employee employee6 = new Employee("Bolanle", "Sorting", + " Sortation Associate", 14000, true); + employee6.displayEmployeeInfo(); + + Employee employee7 = new Employee("Bolajoko", "Recruitment", + " Recruitment Assistant", 11000, true); + employee7.displayEmployeeInfo(); + + Employee employee8 = new Employee("Abdul", "Delivery", + " Delivery Man", 8000, true); + employee8.displayEmployeeInfo(); + + Employee employee9 = new Employee("Abby", "Learning", + " Trainer", 36000, true); + employee9.displayEmployeeInfo(); + + Employee employee10 = new Employee("Adejare", "Instructing", + " Instructor", 8000, true); + employee10.displayEmployeeInfo(); + + + + + // Interns child from Employee Parent Class + + Intern intern1 = new Intern("Tolu", "HR", "HR Intern", 18000, true); + intern1.displayInternInfo(); + intern1.setSalary(50000); + + Intern intern2 = new Intern("Lovey", "Finance", "Finance Intern", 26000, true); + intern2.displayInternInfo(); + + + Intern intern3 = new Intern("Lovey", "Finance", "Finance Intern", 25000, true); + intern3.displayInternInfo(); + + + + + + } + + +} \ No newline at end of file