1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Object-Oriented Programming in Java

Connected

Exercise

Creating a static formula class

In our scenario, we have a Formula class with methods for mathematical formulas that can be useful to many developers using our code. You will add a formula to calculate the speed that will be available for use, thereby ensuring developers using your code do not need to write code for the same speed calculation, saving precious time.

Instructions

100 XP
  • Make the Formula class a static class.
  • Create a static calculateSpeed method that returns a double and takes two double parameters, distance and time.
  • The calculateSpeed method should return the division operation result of distance divided by time.
  • Inside the main method, call the calculateSpeed method of the Formula class, without creating an instance, and print the operation result with the distance parameter set to 165.00 and the time parameter set to 15.00.