Objective Today, we're learning about Interfaces. Check out the Tutorial tab for learning materials and an instructional video! Task The AdvancedArithmetic interface and the method declaration for the abstract divisorSum(n) method are provided for you in the editor below. Complete the implementation of Calculator class, which implements the AdvancedArithmetic interface. The implementation for the divisorSum(n) method must return the sum of all divisors of . Input Format A single line containing an integer, . Constraints Output Format You are not responsible for printing anything to stdout. The locked template code in the editor below will call your code and print the necessary output. Sample Input 6 Sample Output I implemented: AdvancedArithmetic 12 Explanation The integer is evenly divisible by , ,...
Objective Yesterday's challenge taught you to manage exceptional situations by using try and catch blocks. In today's challenge, you're going to practice throwing and propagating an exception. Check out the Tutorial tab for learning materials and an instructional video! Task Write a Calculator class with a single method: int power(int,int) . The power method takes two integers, and , as parameters and returns the integer result of . If either or is negative, then the method must throw an exception with the message: n and p should be non-negative . Note: Do not use an access modifier (e.g.: public) in the declaration for your Calculator class. Input Format Input from stdin is handled for you by the locked stub code in your editor. The first line contains an integer, , the number of test cases. Each of the subseq...
Objective Today we're discussing Generics; be aware that not all languages support this construct , so fewer languages are enabled for this challenge. Task Write a single generic function named printArray ; this function must take an array of generic elements as a parameter (the exception to this is C++, which takes a vector ). The locked Solution class in your editor tests your function. Note: You must use generics to solve this challenge. Do not write overloaded functions. Input Format The locked Solution class in your editor will pass different types of arrays to your printArray function. Constraints You must have exactly function named printArray . Output Format Your printArray function should print each element of its generic array parameter on a new line. Solution : import java.util.*; class Printer <T> { ...
Comments
Post a Comment