




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





class Employee { private String name; private double salary; private String jobTitle; public Employee(String name, double salary, String jobTitle) { this.name = name; this.salary = salary; this.jobTitle = jobTitle; } public String getName() { return name; } public double getSalary() { return salary; } public String getJobTitle() { return jobTitle; } public double calculateBonus() { // Default implementation of bonus calculation return 0.05 * salary; // 5% of salary } } class Manager extends Employee { public Manager(String name, double salary, String jobTitle) { super(name, salary, jobTitle); } @Override public double calculateBonus() { // Override bonus calculation for managers return 0.1 * getSalary(); // 10% of salary
class Engineer extends Employee { public Engineer(String name, double salary, String jobTitle) { super(name, salary, jobTitle); } @Override public double calculateBonus() { // Override bonus calculation for engineers return 0.08 * getSalary(); // 8% of salary } } public class Lab10 { public static void main(String[] args) { Employee employee 1 = new Employee("John", 50000, "Sales Associate"); Manager manager1 = new Manager("Alice", 80000, "Sales Manager"); Engineer engineer1 = new Engineer("Bob", 60000, "Software Engineer"); // Calculate and display bonuses System.out.println("Employee " + employee 1 .getName() + "'s bonus: $"
class Animal1 { public void eat() { System.out.println("Animal is eating."); } public void sound() { System.out.println("Animal makes a sound."); } } class Dog1 extends Animal1 { @Override public void sound() { System.out.println("Dog barks."); } } class Cat extends Animal1 { @Override public void sound() { System.out.println("Cat meows."); } } class Bird extends Animal1 { @Override public void sound() { System.out.println("Bird chirps."); }
public class Lab10 { public static void main(String[] args) { Animal1 animal1 = new Animal1(); Dog1 dog1 = new Dog1(); Cat cat1 = new Cat(); Bird bird1 = new Bird(); // Call eat and sound methods for each animal animal1.eat(); animal1.sound(); System.out.println(); dog1.eat(); dog1.sound(); System.out.println(); cat1.eat(); cat1.sound(); System.out.println(); bird1.eat(); bird1.sound(); } }