diff --git a/week01/src/main/java/com/github/javabaz/Calculator36.java b/week01/src/main/java/com/github/javabaz/Calculator36.java new file mode 100644 index 0000000..ca308d4 --- /dev/null +++ b/week01/src/main/java/com/github/javabaz/Calculator36.java @@ -0,0 +1,186 @@ +package com.github.javabaz; +/** + * Calculator 36 is a boot camp exercise involving basic and + * advanced arithmetic operations such as addition, subtraction, multiplication, division, modulus, power, and square root. + * The primary entry point is the `execute` method, which manages input validation and dispatches, + * The appropriate operation is based on the provided string identifier. + * While helper methods (e.g., add, subtract, power) are public for testing purposes, + * They are intended to be used internally through `execute` to ensure consistent validation. +*/ + + +public class Calculator36 { + private final int minArgs=2; + + public double execute(String operation,double... operands) { + /** + * Executes the specified operation with the given operands. + * This method acts as a centralized dispatcher, handling validation + * of operand counts and delegating to the appropriate computation method. + * + * @param operation the operation to perform (e.g., "add", "subtract", "pow") + * @param operands the numbers to use in the operation + * @return the result of the operation + * @throws IllegalArgumentException if the number of operands is invalid + * @throw UnsupportedOperationException if the operation is not recognized + */ + switch(operation) { + case "pow": + if(operands.length=0;i--) { + result = Math.pow(operands[i],result); + } + return result; + } + + public int getMinArgs() { + /** + * Returns the minimum number of operands required for operations like add, subtract, etc. + * + * @return minimum required operand count + */ + return this.minArgs; + } +}