/
aurelionrg
/
Java
Обзор
Документация
Войти
/
aurelionrg
/
Java
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
SDO
7.java
48 строк
1 KB
aurelionrg
upload files
23 дек 2024, 02:15
23 дек 2024, 02:15
01a2201
Код
Авторство
О чём код?
// Define the MathCalculable interface interface MathCalculable { double PI = 3.141592653589793; double power(double base, int exponent); double modulus(double real, double imaginary); double circumference(double radius); } // Implement the MathCalculable interface in a class class MathFunc implements MathCalculable { @Override public double power(double base, int exponent) { return Math.pow(base, exponent); } @Override public double modulus(double real, double imaginary) { return Math.sqrt(real * real + imaginary * imaginary); } @Override public double circumference(double radius) { return 2 * PI * radius; } } // Test the MathFunc class public class TestMathFunc { public static void main(String[] args) { MathCalculable mc1 = new MathFunc(); // Correct // Demonstrate power function System.out.println("2^3 = " + mc1.power(2, 3)); // Demonstrate modulus function System.out.println("Modulus of (3 + 4i) = " + mc1.modulus(3, 4)); // Demonstrate circumference function System.out.println("Circumference of a circle with radius 5 = " + mc1.circumference(5)); // Uncommenting the below line will produce an error as expected // MathCalculable mc2 = new MathCalculable(); } }