0% found this document useful (0 votes)
6 views

webtech_6[1]

web tech practicle s

Uploaded by

aayush2310008-d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

webtech_6[1]

web tech practicle s

Uploaded by

aayush2310008-d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

(GEETIKA AHUJA 2200271690021)

EXPERIMENT -06
Create a Java Bean for Employee information (EmpID, Name, Salary,
Designation and Department).

CODE:
import java.util.Scanner;

public class Employee {

// Private attributes
private int empID;
private String name;
private double salary;
private String designation;
private String department;

// Default constructor
public Employee() {}

// Parameterized constructor
public Employee(int empID, String name, double salary, String designation,
String department) {
this.empID = empID;
this.name = name;
this.salary = salary;
this.designation = designation;
(GEETIKA AHUJA 2200271690021)

this.department = department;
}

// Getters and Setters


public int getEmpID() { return empID; }
public void setEmpID(int empID) { this.empID = empID; }

public String getName() { return name; }


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

public double getSalary() { return salary; }


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

public String getDesignation() { return designation; }


public void setDesignation(String designation) { this.designation = designation;
}

public String getDepartment() { return department; }


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

// Method to display employee details


public void displayEmployeeDetails() {
System.out.println("\nEmployee Information:");
System.out.println("EmpID: " + empID);
System.out.println("Name: " + name);
System.out.println("Salary: $" + salary);
(GEETIKA AHUJA 2200271690021)

System.out.println("Designation: " + designation);


System.out.println("Department: " + department);
}

// Main method with user interaction


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Welcome to Employee Information System!");

// Prompting user for input


System.out.print("Enter Employee ID: ");
int empID = scanner.nextInt();
scanner.nextLine(); // Consume newline

System.out.print("Enter Employee Name: ");


String name = scanner.nextLine();

System.out.print("Enter Salary: ");


double salary = scanner.nextDouble();
scanner.nextLine(); // Consume newline

System.out.print("Enter Designation: ");


String designation = scanner.nextLine();

System.out.print("Enter Department: ");


(GEETIKA AHUJA 2200271690021)

String department = scanner.nextLine();

// Create Employee object using input data


Employee employee = new Employee(empID, name, salary, designation,
department);

// Display the employee information


employee.displayEmployeeDetails();

// Offer the user the option to update any employee detail


System.out.println("\nWould you like to update any details? (yes/no)");
String choice = scanner.nextLine();

if (choice.equalsIgnoreCase("yes")) {
System.out.println("What would you like to update?");
System.out.println("1. EmpID");
System.out.println("2. Name");
System.out.println("3. Salary");
System.out.println("4. Designation");
System.out.println("5. Department");
System.out.print("Enter your choice (1-5): ");

int updateChoice = scanner.nextInt();


scanner.nextLine(); // Consume newline

switch (updateChoice) {
case 1:
(GEETIKA AHUJA 2200271690021)

System.out.print("Enter new EmpID: ");


employee.setEmpID(scanner.nextInt());
break;
case 2:
System.out.print("Enter new Name: ");
employee.setName(scanner.nextLine());
break;
case 3:
System.out.print("Enter new Salary: ");
employee.setSalary(scanner.nextDouble());
break;
case 4:
System.out.print("Enter new Designation: ");
employee.setDesignation(scanner.nextLine());
break;
case 5:
System.out.print("Enter new Department: ");
employee.setDepartment(scanner.nextLine());
break;
default:
System.out.println("Invalid choice.");
break;
}

// Display updated employee information


employee.displayEmployeeDetails();
(GEETIKA AHUJA 2200271690021)

} else {
System.out.println("Thank you! No changes made.");
}

scanner.close();
(GEETIKA AHUJA 2200271690021)
(GEETIKA AHUJA 2200271690021)

You might also like