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
116 changes: 116 additions & 0 deletions src/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
public class Employee {

// Private instance variables
private int employeeId;
private String firstName;
private String lastName;
private String email;
private String phoneNumber;
private String jobTitle;
private double salary;

// Constructor
public Employee(int employeeId, String firstName, String lastName, String email,
String phoneNumber, String jobTitle, double salary) {
this.employeeId = employeeId;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.phoneNumber = phoneNumber;
this.jobTitle = jobTitle;
setSalary(salary); // Using setter to apply validation
}

// Getter and Setter methods
public int getEmployeeId() {
return employeeId;
}

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

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getJobTitle() {
return jobTitle;
}

public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
if (salary >= 0) {
this.salary = salary;
} else {
throw new IllegalArgumentException("Salary must be non-negative.");
}
}

// Behaviors
public void work() {
System.out.println(firstName + " " + lastName + " is working as a " + jobTitle + ".");
}

public double getAnnualSalary() {
return salary * 12;
}

public void raiseSalary(double percentage) {
if (percentage > 0) {
salary += salary * (percentage / 100);
} else {
throw new IllegalArgumentException("Raise percentage must be positive.");
}
}

@Override
public String toString() {
return "Employee{" +
"employeeId=" + employeeId +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", jobTitle='" + jobTitle + '\'' +
", salary=" + salary +
'}';
}
}


43 changes: 43 additions & 0 deletions src/ExerciseFiveApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
public class ExerciseFiveApplication {

public static void main(String[] args) {
Intern intern= new Intern(146, "Sten", "Mabel", "sten@gmail.com", "+2387878434", "IT-Specialist Intern", 40000);
Intern intern2= new Intern(2445, "Sara", "Kie", "kie@hotmail.com", "0492323457", "HR-Specialist Intern", 35000);
Intern intern3= new Intern(3555, "Luca", "kelvin", "luca@yahoo.com", "+99876345", "Marketing Specialist Intern", 42000);
System.out.println(intern);
System.out.println(intern2);
System.out.println(intern3);
// Array to hold 10 Employee objects
Employee[] employees = new Employee[10];

// Initialize each Employee object with sample data
employees[0] = new Employee(101, "Alice", "Smith", "alice.smith@example.com",
"123-456-7890", "Software Engineer", 70000);
employees[1] = new Employee(102, "Bob", "Johnson", "bob.johnson@example.com",
"234-567-8901", "Data Analyst", 65000);
employees[2] = new Employee(103, "Charlie", "Williams", "charlie.williams@example.com",
"345-678-9012", "Product Manager", 80000);
employees[3] = new Employee(104, "David", "Brown", "david.brown@example.com",
"456-789-0123", "UX Designer", 72000);
employees[4] = new Employee(105, "Eva", "Davis", "eva.davis@example.com",
"567-890-1234", "Quality Assurance", 68000);
employees[5] = new Employee(106, "Frank", "Miller", "frank.miller@example.com",
"678-901-2345", "DevOps Engineer", 75000);
employees[6] = new Employee(107, "Grace", "Wilson", "grace.wilson@example.com",
"789-012-3456", "HR Manager", 71000);
employees[7] = new Employee(108, "Hannah", "Moore", "hannah.moore@example.com",
"890-123-4567", "Marketing Specialist", 69000);
employees[8] = new Employee(109, "Ian", "Taylor", "ian.taylor@example.com",
"901-234-5678", "Sales Executive", 67000);
employees[9] = new Employee(110, "Jane", "Anderson", "jane.anderson@example.com",
"012-345-6789", "Customer Support", 64000);

// Iterate through the array and print details of each employee
for (Employee emp : employees) {
System.out.println(emp);
System.out.println("-------------------------------");
}
}
}


24 changes: 24 additions & 0 deletions src/ExerciseFour.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class ExerciseFour {
public static void main(String[] args) {
// Creating an Employee object
Employee emp = new Employee(1010, "Olu", "Tosin", "tosin@gmail.com",
"015212099501", "Operational Lead", 45000);

// Displaying employee details
System.out.println("Employee ID: " + emp.getEmployeeId());
System.out.println("Name: " + emp.getFirstName() + " " + emp.getLastName());
System.out.println("Email: " + emp.getEmail());
System.out.println("Phone: " + emp.getPhoneNumber());
System.out.println("Job Title: " + emp.getJobTitle());
System.out.println("Monthly Salary: $" + emp.getSalary());
System.out.println("Annual Salary: $" + emp.getAnnualSalary());

// Simulating work
emp.work();

// Giving a raise
emp.raiseSalary(35);
System.out.println("New Monthly Salary after 35% raise: $" + emp.getSalary());

}
}
31 changes: 31 additions & 0 deletions src/ExerciseOneApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class ExerciseOneApplication {
public static int findDiff(int[] numbers) {
// Validate that the array has at least one element
if (numbers == null || numbers.length == 0) {
System.out.println("list of values"); ;
}

// Initialize min and max with the first element of the array
int min = numbers[0];
int max = numbers[0];

// Iterate through the array to find the minimum and maximum values
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] < min) {
min = numbers[i];
} else if (numbers[i] > max) {
max = numbers[i];
}
}

// Return the difference between the maximum and minimum values
return max - min;
}

public static void main(String[] args) {
int[] array = {18, 56, 27, 99, 53};
int difference = findDiff(array);
System.out.println("Difference between values: " + difference);
}
}

37 changes: 37 additions & 0 deletions src/ExerciseTwoApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class ExerciseTwoApplication {
public static void findValue(int[] array) {
// Check if the array has at least two elements
if (array == null || array.length < 2) {
System.out.println("Array must contain at least two elements.");
return;
}

// Initialize the smallest and second smallest with maximum possible values
int smallest = Integer.MAX_VALUE;
int secondSmallest = Integer.MAX_VALUE;

// Iterate through the array to find the smallest and second smallest elements
for (int num : array) {
if (num < smallest) {
secondSmallest = smallest;
smallest = num;
} else if (num > smallest && num < secondSmallest) {
secondSmallest = num;
}
}

// Check if a valid second smallest element was found
if (secondSmallest == Integer.MAX_VALUE) {
System.out.println("No distinct second smallest element found.");
} else {
System.out.println("The smallest element is " + smallest +
" and the second smallest element is " + secondSmallest + ".");
}
}

public static void main(String[] args) {
int[] array = {52, 77, -8, 12, 14, 31};
findValue(array);
}
}

18 changes: 18 additions & 0 deletions src/Intern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Intern extends Employee{

private final double MAX_SALARY = 20_000.0;

public Intern(int employeeId, String firstName, String lastName, String email, String phoneNumber, String jobTitle, double salary) {
super(employeeId, firstName, lastName, email, phoneNumber, jobTitle, salary);
if (salary > MAX_SALARY){
this.setSalary(MAX_SALARY);
}
}

@Override
public String toString() {
return "Intern{" +
"MAX_SALARY=" + MAX_SALARY +
"} " + super.toString();
}
}