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
Binary file added .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/lab-java-basics.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added out/production/lab-java-basics/Task1/Main.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Task2/Main.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/lab-java-basics/Task3/Main.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/lab-java-basics/Task4/Intern.class
Binary file not shown.
Binary file added out/production/lab-java-basics/Task4/Main.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/lab-java-basics/Task5/Main.class
Binary file not shown.
22 changes: 22 additions & 0 deletions src/Task1/Main.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
27 changes: 27 additions & 0 deletions src/Task2/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 16 additions & 0 deletions src/Task3/Employee.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
18 changes: 18 additions & 0 deletions src/Task3/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
31 changes: 31 additions & 0 deletions src/Task4/Employee.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
20 changes: 20 additions & 0 deletions src/Task4/Intern.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
18 changes: 18 additions & 0 deletions src/Task4/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
67 changes: 67 additions & 0 deletions src/Task5/Employees.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
37 changes: 37 additions & 0 deletions src/Task5/Main.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}