Created
October 16, 2023 01:05
-
-
Save abdorll/4a6ab3ae5a24f86189650bf2efe6a41b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee { | |
String? name; | |
int? age; | |
String? department; | |
double? salary; | |
// Constructor | |
Employee(String name, int age, String department, double salary) { | |
this.name = name; | |
this.age = age; | |
this.department = department; | |
this.salary = salary; | |
} | |
// Method to display employee details | |
void display() { | |
print("Name: ${this.name}"); | |
print("Age: ${this.age}"); | |
print("Department: ${this.department}"); | |
print("Salary: ${this.salary}\n"); | |
} | |
// Method to give an annual raise | |
void giveRaise(double percentage) { | |
double raiseAmount = this.salary! * (percentage / 100); | |
this.salary = this.salary! + raiseAmount; | |
} | |
} | |
void main() { | |
// Creating an employee object of class Employee | |
Employee employee1 = Employee("Alice", 28, "HR", 45000.0); | |
employee1.display(); | |
// Applying an annual raise | |
employee1.giveRaise(5); // Giving a 5% raise | |
employee1.display(); | |
// Creating another employee object | |
Employee employee2 = Employee("Bob", 32, "Engineering", 60000.0); | |
employee2.display(); | |
// Applying an annual raise | |
employee2.giveRaise(7); // Giving a 7% raise | |
employee2.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment