diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..248021f Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/lab-java-basics.iml b/.idea/lab-java-basics.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/.idea/lab-java-basics.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a20905f --- /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/out/production/lab-java-basics/Task1/Main.class b/out/production/lab-java-basics/Task1/Main.class new file mode 100644 index 0000000..9f11761 Binary files /dev/null and b/out/production/lab-java-basics/Task1/Main.class differ diff --git a/out/production/lab-java-basics/Task2/Main.class b/out/production/lab-java-basics/Task2/Main.class new file mode 100644 index 0000000..eab27e6 Binary files /dev/null and b/out/production/lab-java-basics/Task2/Main.class differ diff --git a/out/production/lab-java-basics/Task3/Employee.class b/out/production/lab-java-basics/Task3/Employee.class new file mode 100644 index 0000000..dcb51d5 Binary files /dev/null and b/out/production/lab-java-basics/Task3/Employee.class differ diff --git a/out/production/lab-java-basics/Task3/Main.class b/out/production/lab-java-basics/Task3/Main.class new file mode 100644 index 0000000..d1f471e Binary files /dev/null and b/out/production/lab-java-basics/Task3/Main.class differ diff --git a/out/production/lab-java-basics/Task4/Employee.class b/out/production/lab-java-basics/Task4/Employee.class new file mode 100644 index 0000000..d65ff4d Binary files /dev/null and b/out/production/lab-java-basics/Task4/Employee.class differ diff --git a/out/production/lab-java-basics/Task4/Intern.class b/out/production/lab-java-basics/Task4/Intern.class new file mode 100644 index 0000000..2e58e10 Binary files /dev/null and b/out/production/lab-java-basics/Task4/Intern.class differ diff --git a/out/production/lab-java-basics/Task4/Main.class b/out/production/lab-java-basics/Task4/Main.class new file mode 100644 index 0000000..0015c1a Binary files /dev/null and b/out/production/lab-java-basics/Task4/Main.class differ diff --git a/out/production/lab-java-basics/Task5/Employees.class b/out/production/lab-java-basics/Task5/Employees.class new file mode 100644 index 0000000..4d268ca Binary files /dev/null and b/out/production/lab-java-basics/Task5/Employees.class differ diff --git a/out/production/lab-java-basics/Task5/Main.class b/out/production/lab-java-basics/Task5/Main.class new file mode 100644 index 0000000..3abe330 Binary files /dev/null and b/out/production/lab-java-basics/Task5/Main.class differ diff --git a/src/Task1/Main.java b/src/Task1/Main.java new file mode 100644 index 0000000..f002c09 --- /dev/null +++ b/src/Task1/Main.java @@ -0,0 +1,22 @@ +package Task1; + +public class Main { + + public static int difference(int[] numbers) { + int min = numbers[0]; + int max = numbers[0]; + + for (int num : numbers) { + if (num < min) min = num; + if (num > max) max = num; + } + + + return max - min; + } + + public static void main(String[] args) { + int[] arr = {5, 2, 9, 1, 7}; + System.out.println("Difference: " + difference(arr)); + } +} \ No newline at end of file diff --git a/src/Task2/Main.java b/src/Task2/Main.java new file mode 100644 index 0000000..1ecf75f --- /dev/null +++ b/src/Task2/Main.java @@ -0,0 +1,27 @@ +package Task2; + +public class Main { + + public static void main(String[] args) { + int[] arr = {5, 2, 9, 1, 7}; + + findTwoSmallest(arr); + } + + public static void findTwoSmallest(int[] numbers) { + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + + for (int num : numbers) { + if (num < smallest) { + secondSmallest = smallest; + smallest = num; + } else if (num < secondSmallest && num != smallest) { + secondSmallest = num; + } + } + + System.out.println("Smallest: " + smallest); + System.out.println("Second Smallest: " + secondSmallest); + } +} \ No newline at end of file diff --git a/src/Task3/Employee.java b/src/Task3/Employee.java new file mode 100644 index 0000000..63f1c9a --- /dev/null +++ b/src/Task3/Employee.java @@ -0,0 +1,16 @@ +package Task3; + +public class Employee { + + String name; + double salary; + + public void displayInfo() { + System.out.println("Name: " + name); + System.out.println("Salary: " + salary); + } + + public void increaseSalary(double amount) { + salary += amount; + } +} \ No newline at end of file diff --git a/src/Task3/Main.java b/src/Task3/Main.java new file mode 100644 index 0000000..d91048b --- /dev/null +++ b/src/Task3/Main.java @@ -0,0 +1,18 @@ +package Task3; + +public class Main { + + public static void main(String[] args) { + + Employee emp1 = new Employee(); + emp1.name = "Hadi"; + emp1.salary = 3000; + + emp1.displayInfo(); + + System.out.println("---- After Increase ----"); + + emp1.increaseSalary(500); + emp1.displayInfo(); + } +} \ No newline at end of file diff --git a/src/Task4/Employee.java b/src/Task4/Employee.java new file mode 100644 index 0000000..380043c --- /dev/null +++ b/src/Task4/Employee.java @@ -0,0 +1,31 @@ +package Task4; + +public class Employee { + + private String name; // Employee name + private double salary; // Employee salary + + public Employee(String name, double salary) { + this.name = name; + this.salary = salary; + } + + public String getName() { + return name; + } + + public double getSalary() { + return salary; + } + + public void setSalary(double salary) { + if (salary > 0) { // Only positive salary allowed + this.salary = salary; + } + } + + public void displayInfo() { + System.out.println("Name: " + name); + System.out.println("Salary: " + salary); + } +} \ No newline at end of file diff --git a/src/Task4/Intern.java b/src/Task4/Intern.java new file mode 100644 index 0000000..72d6cf7 --- /dev/null +++ b/src/Task4/Intern.java @@ -0,0 +1,20 @@ +package Task4; + +public class Intern extends Employee { + + private static final double MAX_SALARY = 20000; // Maximum allowed salary + + public Intern(String name, double salary) { + super(name, 0); // Initialize salary to 0 first + setSalary(salary); // Set salary with validation + } + + @Override + public void setSalary(double salary) { + if (salary <= MAX_SALARY) { + super.setSalary(salary); // Apply salary if within limit + } else { + System.out.println("Salary exceeds max limit of " + MAX_SALARY); + } + } +} \ No newline at end of file diff --git a/src/Task4/Main.java b/src/Task4/Main.java new file mode 100644 index 0000000..ec05495 --- /dev/null +++ b/src/Task4/Main.java @@ -0,0 +1,18 @@ +package Task4; + +public class Main { + + public static void main(String[] args) { + + Intern intern1 = new Intern("Parsa", 15000); + intern1.displayInfo(); + + System.out.println("Trying to increase salary to 25000"); + intern1.setSalary(25000); // Should not change + intern1.displayInfo(); + + System.out.println("Updating salary to 18000"); + intern1.setSalary(18000); // Should apply + intern1.displayInfo(); + } +} \ No newline at end of file diff --git a/src/Task5/Employees.java b/src/Task5/Employees.java new file mode 100644 index 0000000..a74ce1b --- /dev/null +++ b/src/Task5/Employees.java @@ -0,0 +1,67 @@ +package Task5; + +// Employees class with full properties +public class Employees { + + private String name; + private double salary; + private int age; + private int experience; // years of experience + private String department; + + // Constructor + public Employees(String name, double salary, int age, int experience, String department) { + this.name = name; + this.salary = salary; + this.age = age; + this.experience = experience; + this.department = department; + } + + // Getters + public String getName() { + return name; + } + + public double getSalary() { + return salary; + } + + public int getAge() { + return age; + } + + public int getExperience() { + return experience; + } + + public String getDepartment() { + return department; + } + + // Setters + public void setSalary(double salary) { + if (salary > 0) this.salary = salary; + } + + public void setAge(int age) { + if (age > 0) this.age = age; + } + + public void setExperience(int experience) { + if (experience >= 0) this.experience = experience; + } + + public void setDepartment(String department) { + this.department = department; + } + + + public void displayInfo() { + System.out.println("Name: " + name + + " | Salary: " + salary + + " | Age: " + age + + " | Experience: " + experience + + " | Department: " + department); + } +} \ No newline at end of file diff --git a/src/Task5/Main.java b/src/Task5/Main.java new file mode 100644 index 0000000..6206e1a --- /dev/null +++ b/src/Task5/Main.java @@ -0,0 +1,37 @@ +package Task5; + +public class Main { + + public static void main(String[] args) { + + Object[][] data = { + {"Saba", 59000.0, 31, 2, "AI"}, + {"Hadi", 58000.0, 33, 3, "IT"}, + {"Sepehr", 48000.0, 28, 3, "Marketing"}, + {"Sohrab", 49000.0, 40, 15, "HR"}, + {"Siavash", 52000.0, 32, 7, "IT"}, + {"Fereydoon", 47000.0, 27, 2, "Finance"}, + {"George", 53000.0, 34, 8, "Marketing"}, + {"Pooran", 49000.0, 29, 4, "HR"}, + {"Sara", 51000.0, 31, 6, "IT"}, + {"Parsa", 56000.0, 38, 12, "Finance"}, + {"Babak", 56000.0, 38, 12, "Marketing"} + }; + + Employees[] employees = new Employees[data.length]; + + for (int i = 0; i < data.length; i++) { + String name = (String) data[i][0]; + double salary = (double) data[i][1]; + int age = (int) data[i][2]; + int exp = (int) data[i][3]; + String dept = (String) data[i][4]; + + employees[i] = new Employees(name, salary, age, exp, dept); + } + + for (Employees emp : employees) { + emp.displayInfo(); + } + } +} \ No newline at end of file