0% found this document useful (0 votes)
6 views3 pages

Program 3

The document outlines a Java program that defines an Employee class with attributes for ID, name, and salary, along with methods to read employee details and raise salaries by a given percentage. The main method demonstrates the functionality by allowing user input for multiple employees, displaying their details before and after salary raises. The program showcases the use of arrays and basic input/output operations in Java.

Uploaded by

tanushree9663
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 views3 pages

Program 3

The document outlines a Java program that defines an Employee class with attributes for ID, name, and salary, along with methods to read employee details and raise salaries by a given percentage. The main method demonstrates the functionality by allowing user input for multiple employees, displaying their details before and after salary raises. The program showcases the use of arrays and basic input/output operations in Java.

Uploaded by

tanushree9663
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/ 3

/*

Program 3:
A class called Employee, which models an employee with an ID,
name and salary, is designed as shown in the following class
diagram. The method raiseSalary (percent) increases the salary
by the given percentage.
Develop the Employee class and suitable main method for
demonstration.
*/
import [Link];

class Employee {
​ String ID;
​ String name;
​ double salary;

​ void read(Scanner scan) {
​ ​ [Link]("ID : ");
​ ​ ID = [Link]();
​ ​
​ ​ [Link]("Name : ");
​ ​ name = [Link]();
​ ​
​ ​ [Link]("Salary: ");
​ ​ salary = [Link]();
​ }

​ double raiseSalary(double p) {
​ ​ ​
​ ​ salary += salary * p;
​ ​ return salary;
​ } //End raiseSalary​

​ public void display() {


​ ​ [Link]("%5s %10s %10.2f \n",ID, name, salary);
​ }

} //End Employee

public class EmployeeDemo {


​ public static void main(String[] args) {

​ ​ int i, j;​ ​
​ ​
​ ​ Scanner scan = new Scanner([Link]);
​ ​
​ ​ [Link]("Enter number of employees: ");
​ ​ int n = [Link]();
​ ​ Employee emp[] = new Employee[n];
​ ​
​ ​ //Read Employee details
​ ​ [Link]("Enter employee details: ");
​ ​ for(i = 0; i < n; i++) {
​ ​ ​ [Link]("\nEmployee "+ (i+1) +": ");
​ ​ ​
​ ​ ​ emp[i] = new Employee();
​ ​ ​ emp[i].read(scan);
​ ​ }
​ ​
​ ​ //Display Employee details before Salary Raise
​ ​ [Link]("\nEmployee details(before Salary Raise): ");
​ ​ [Link]("%5s %10s %10s \n","ID","Name","Salary");
​ ​ for(i = 0; i < n; i++) {
​ ​ ​ emp[i].display();
​ ​ }
​ ​
​ ​ //Employee Salary Raise
​ ​ [Link]("\nEmployee Salary Raise(%): ");
​ ​ for(i = 0; i < n; i++) {
​ ​ ​ [Link]("Employee "+ (i+1) +": ");​ ​ ​
​ ​ ​
​ ​ ​ double raise = [Link]();
​ ​ ​ emp[i].raiseSalary(raise/100);
​ ​ }
​ ​
​ ​ //Display Employee details (after Salary Raise)
​ ​ [Link]("\nEmployee details(after Salary Raise): ");
​ ​ [Link]("%5s %10s %10s \n","ID","Name","Salary");
​ ​ for(i = 0; i < n; i++) {
​ ​ ​ emp[i].display();
​ ​ }
​ } //End main
} // End EmployeeDemo

/*
Output:
Enter number of employees: 3
Enter employee details:
Employee 1:
ID : 100
Name : Person1
Salary: 100000

Employee 2:
ID : 101
Name : Person2
Salary: 150000

Employee 3:
ID : 102
Name : Person3
Salary: 200000

Employee details(before Salary Raise):


ID Name Salary
100 Person1 100000.00
101 Person2 150000.00
102 Person3 200000.00

Employee Salary Raise(%):


Employee 1: 10
Employee 2: 15
Employee 3: 20

Employee details(after Salary Raise):


ID Name Salary
100 Person1 110000.00
101 Person2 172500.00
102 Person3 240000.00
*/

You might also like