Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Java Annotations - Practice Level 1

πŸ“Œ Introduction

Java annotations provide metadata about the code and help in various scenarios like overriding methods, suppressing warnings, and more. This practice focuses on understanding how Java annotations work.

πŸ“‹ Exercises

πŸ”Ή Exercise 1: Hierarchy of Workers

Create a hierarchy of objects with three classes: Worker, OnlineWorker, and OnSiteWorker.

  • The Worker class should have attributes name, surname, hourlyRate, and a method calculateSalary() that takes the number of hours worked as a parameter and returns the salary.
  • The subclasses should override calculateSalary(), using the @Override annotation.
  • In the main() method of the Principal class, make the necessary calls to demonstrate the functionality of @Override.

🏒 OnSite Workers

  • Their calculateSalary() method will take the number of hours worked per month as a parameter.
  • Salary calculation: (hoursWorked * hourlyRate) + gasolineBonus.
  • gasolineBonus should be a static attribute in this class.

πŸ’» Online Workers

  • Their calculateSalary() method will also take the number of hours worked per month as a parameter.
  • Salary calculation: (hoursWorked * hourlyRate) + internetFlatRate.
  • internetFlatRate should be a constant in OnlineWorker.

πŸ”Ή Exercise 2: Deprecated Methods

  • Add some deprecated methods to the subclasses and use the @Deprecated annotation.
  • From an external class, invoke these deprecated methods while suppressing warnings using the appropriate annotation.

🎯 Objectives

  • Learn how Java annotations work.
  • Understand the use of @Override in method overriding.
  • Apply @Deprecated to mark outdated methods.
  • Use annotations to suppress warnings when needed.

πŸ›  Project Details

  • Java Version: Jbr17

  • IDE: IntelliJ IDEA (Recommended, but any IDE can be used)

  • Can also be run from the console using appropriate commands

    πŸ“ Clone the repository

Happy coding! πŸš€

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages