Write a Calculator class with a single method: int power(int,int). The power method takes two integers, n and p, as parameters and returns the integer result of n^p. If either n or p is negative, then the method must throw an exception with the message: n and p should be non-negative.
Tag: java
Day 16: Exceptions – String to Integer(30 Days of Code)
Read a string, S, and print its integer value; if cannot be converted to an integer, print Bad String.
Note: You must use the String-to-Integer and exception handling constructs built into your submission language. If you attempt to use loops/conditional statements, you will get a 0 score.
Day 15: Linked List (30 Days of Code)
Complete the insert function in your editor so that it creates a new Node (pass data as the Node constructor argument) and inserts it at the tail of the linked list referenced by the head parameter. Once the new node is added, return the reference to the head node.
Note: The head argument is null for an empty list.
Day 14: Scope(30 Days of Code)
Complete the Difference class by writing the following:
A class constructor that takes an array of integers as a parameter and saves it to the __elements instance variable.
A computeDifference method that finds the maximum absolute difference between any 2 numbers in __elements and stores it in the maximumDifference instance variable.
Day 13: Abstract Classes (30 Days of Code)
Task Given a Book class and a Solution class, write a MyBook class that does the following: Inherits from Book Has a parameterized constructor taking these 3 parameters: string title … Read more
Day 12: Inheritance (30 Days of Code)
Task You are given two classes, Person and Student, where Person is the base class and Student is the derived class. Completed code for Person and a declaration for Student are … Read more
Sparse Arrays (Problem Solving: Data-Structures)
Task: There is a collection of input strings and a collection of query strings. For each query string, determine how … Read more
Left Rotation(Problem Solving: Data-Structures)
Task: A left rotation operation on an array of size n shifts each of the array’s elements 1 unit to the left. Given an integer,d, rotate … Read more
Arrays – DS
Task: An array is a type of data structure that stores elements of the same type in a contiguous block of memory. … Read more
Day 10: Binary Numbers (30 Days of Code)
Task: Given a base- integer,n , convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of … Read more