Я пытался запустить этот код, но он не работает.
Вы должны создать калькулятор с его основными функциями.
Создать класс калькулятора, в котором есть сумма, вычитание, деление иметоды умножения, все они принимают два параметра типа int и возвращают полученное значение типа int.
Пример. Когда метод sum вызывается как sum (5,6), он должен возвращать 11, которое является суммой 5 и 6.
Как я могу это исправить?
class MyCalculator {
int input1 = 15;
int input2 = 5;
public float sum() {
int sum = input1 + input2;
return sum;
}
public float divid() {
// TODO: write java code to calculate the average for all input variables
int divid = (input1 / input2);
return divid;
}
public float subtract() {
// TODO: write java code to calculate the average for all input variables
int subtract = (input1 - input2);
return subtract;
}
public float multiply() {
// TODO: write java code to calculate the average for all input variables
int multiply = (input1 * input2);
return multiply;
}
}
Это дает мне эту ошибку
method sum in class MyCalculator cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length
method divid in class MyCalculator cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length
method subtract in class MyCalculator cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length
method multiply in class MyCalculator cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length