mirror of
https://github.com/Manoj-HV30/OOPS-lab-codes.git
synced 2026-05-16 19:35:25 +00:00
first code
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,109 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
class Employee {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
int empId;
|
||||||
|
String department;
|
||||||
|
int age;
|
||||||
|
String designation;
|
||||||
|
double salary;
|
||||||
|
|
||||||
|
// Method to read employee details
|
||||||
|
void readEmployee(Scanner sc) {
|
||||||
|
System.out.print("Enter Name: ");
|
||||||
|
name = sc.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Enter Employee ID: ");
|
||||||
|
empId = sc.nextInt();
|
||||||
|
sc.nextLine(); // consume newline
|
||||||
|
|
||||||
|
System.out.print("Enter Department: ");
|
||||||
|
department = sc.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Enter Age: ");
|
||||||
|
age = sc.nextInt();
|
||||||
|
sc.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Enter Designation: ");
|
||||||
|
designation = sc.nextLine();
|
||||||
|
|
||||||
|
System.out.print("Enter Salary: ");
|
||||||
|
salary = sc.nextDouble();
|
||||||
|
sc.nextLine();
|
||||||
|
|
||||||
|
System.out.println("---------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to display employee details
|
||||||
|
void displayEmployee() {
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
System.out.println("Employee ID: " + empId);
|
||||||
|
System.out.println("Department: " + department);
|
||||||
|
System.out.println("Age: " + age);
|
||||||
|
System.out.println("Designation: " + designation);
|
||||||
|
System.out.println("Salary: " + salary);
|
||||||
|
System.out.println("---------------------------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EmployeeDatabase {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
int n = 5; // minimum 5 employees
|
||||||
|
Employee[] emp = new Employee[n];
|
||||||
|
|
||||||
|
// Read employee details
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
System.out.println("\nEnter details of Employee " + (i + 1));
|
||||||
|
emp[i] = new Employee();
|
||||||
|
emp[i].readEmployee(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display all employee details
|
||||||
|
System.out.println("\n===== Employee Details =====");
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
emp[i].displayEmployee();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate total salary of Sales department
|
||||||
|
double salesTotal = 0;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (emp[i].department.equalsIgnoreCase("Sales")) {
|
||||||
|
salesTotal += emp[i].salary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Total Salary of Sales Department: " + salesTotal);
|
||||||
|
|
||||||
|
// Find highest paid Manager in Purchase department
|
||||||
|
Employee highestPaidManager = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (
|
||||||
|
emp[i].department.equalsIgnoreCase("Purchase") &&
|
||||||
|
emp[i].designation.equalsIgnoreCase("Manager")
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
highestPaidManager == null ||
|
||||||
|
emp[i].salary > highestPaidManager.salary
|
||||||
|
) {
|
||||||
|
highestPaidManager = emp[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display result
|
||||||
|
if (highestPaidManager != null) {
|
||||||
|
System.out.println(
|
||||||
|
"\n===== Highest Paid Manager in Purchase Department ====="
|
||||||
|
);
|
||||||
|
highestPaidManager.displayEmployee();
|
||||||
|
} else {
|
||||||
|
System.out.println("\nNo Manager found in Purchase Department.");
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user