Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Fill in the blanks to complete a Calculator class that performs basic arithmetic operations. The class should handle null inputs and division by zero gracefully. What should go in each blank to make the code work correctly?Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClasses and objectsObjects
Wrapping classes. Boxing
The arithmetic whisperer's challenge
Report a typo
Fill in the gaps with the relevant elements
Calculator {
public int calculate( a, Integer b, operation) {
int x = (a != null) ? a : 0;
int y = (b != null) ? b : 0;
switch (operation) {
case '+': return x + y;
case '-': return x - y;
case '*': return x * y;
case '/': return (y != 0) ? x / y : 0;
default: return 0;
}
}
}Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.