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
23 changes: 23 additions & 0 deletions Question1/Solution1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Question1;

public class Solution1 {
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 = {8,2,15,6};
System.out.println("Difference: " + getDifference(numbers));
}
}
31 changes: 31 additions & 0 deletions Question2/Solution2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package Question2;

public class Solution2 {
public static void main(String[] args) {
int[] arr = {15,2,6,7,9,10};

if (arr.length < 2) {
System.out.println("Array must have at least three elements.");
return;
}

int smallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;

for (int i = 0; i < arr.length; i++) {
if (arr[i] < smallest){
secondSmallest = smallest;
smallest = arr[i];
} else if (arr[i] < secondSmallest && arr[i] != smallest) {
secondSmallest = arr[i];
}
}

if (secondSmallest == Integer.MAX_VALUE) {
System.out.println("No second smallest element (all elements may be equal).");
} else {
System.out.println("Smallest element: " + smallest);
System.out.println("Second smallest element: " + secondSmallest);
}
}
}
79 changes: 79 additions & 0 deletions Questions345/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package Questions345;
public class Employee {
private int employeeId;
private String name;
private int age;
private String department;
private double salary;

public Employee(int employeeId, String name, int age, String department, double salary) {
this.employeeId = employeeId;
this.name = name;
this.age = age;
this.department = department;
this.salary = salary;
}

public int getEmployeeId() {
return employeeId;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public String getDepartment() {
return department;
}

public double getSalary() {
return salary;
}

public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}

public void setDepartment(String department) {
this.department = department;
}

public void setSalary (double salary) {
this.salary = salary;
}

public void giveRaise(double amount){
if (amount > 0){
salary += amount;
}
}

public void displayInfo() {
System.out.println("Employee ID: " + employeeId);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Department: " + department);
System.out.println("Salary: " + salary);
}
}









44 changes: 44 additions & 0 deletions Questions345/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package Questions345;
public class Intern extends Employee {
public static final double MAX_SALARY = 20000.0;

public Intern(int employeeId, String name, int age, String department, double salary) {
super(employeeId, name, age, department, validateSalary(salary));
}

// Optional getter for MAX_SALARY
public static double getMaxSalary() {
return MAX_SALARY;
}

// Validate salary so it never exceeds MAX_SALARY
private static double validateSalary(double salary) {
if (salary > MAX_SALARY) {
System.out.println("Salary exceeds maximum allowed for Intern. Setting to " + MAX_SALARY);
return MAX_SALARY;
}
return salary;
}

@Override
public void setSalary(double salary) {
super.setSalary(validateSalary(salary));
}

@Override
public void giveRaise(double amount) {
if (amount > 0) {
double newSalary = getSalary() + amount;
super.setSalary(validateSalary(newSalary));
}
}

@Override
public void displayInfo() {
System.out.println("== Intern Info ==");
super.displayInfo();
}
}



25 changes: 25 additions & 0 deletions Questions345/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Questions345;
public class Main {
public static void main(String[] args) {
Employee[] employees = new Employee[10];

employees[0] = new Employee(313, "Jason Smith", 45, "IT", 60000 );
employees[1] = new Employee(205, "Alice Jones", 34, "HR", 36000 );
employees[2] = new Employee(101, "Max Backer", 25, "Finance", 53000);
employees[3] = new Employee(203, "Amanda Gilmore", 40,"Marketing", 55000);
employees[4] = new Employee(105, "Lilian Dalton", 30, "Sales", 56000);
employees[5] = new Employee(308, "Henry Decker", 35,"HR Manager",65000);
employees[6] = new Employee(103, "Emily Wu", 29, "IT",65000);
employees[7] = new Employee(210, "Taylor Wiggins", 33, "Marketing", 58000);
employees[8] = new Employee(305, "Liana Barber", 22, "Finance", 20000);
employees[9] = new Employee(113, "Brodie Harding", 50, "Manager", 80000);

System.out.println("=== Employee List ===");
for (int i = 0; i < employees.length; i++) {
System.out.println(" Employee #" + (i + 1));
employees[i].displayInfo();
System.out.println("----------------------");
}

}
}