ComeçarComece de graça

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.

Este exercício faz parte do curso

Introduction to Object-Oriented Programming in Java

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

public class Main {
	// Mark Formula static
    ___ class Formula{
    
        // Create the calculateSpeed static method
        ___ ___ ___(___ ___, ___ ___) {
          ___ ____ / ___;
        }            
    
    }

    public static void main(String[] args) {
        // Print the result of the calculateSpeed method with the correct parameters
        System.out.println(Formula.___(___, ___));
    }
}
Editar e executar o código