Consider the IntArrayBag data structure that is represented by the following UML. IntArrayBag -data:int[] -manyltems:int +IntArrayBag() +IntArrayBag(capacity:int) +add(element:int):void +countOcuurances(target:int):int +grab(index:i):int +remove(target:int):void +size():int +max():int +countEven():int +change(oldVal:int, newVal:int):int (1) Implement an instance method, called bagMax, in the IntArrayBag class that finds and return the maximum value in the bag. (2) Implement an instance method, called equals To, in the IntArrayBag's class that takes one input parameter and returns a boolean value. The input parameter, called otherBag, is of type IntArrayBag as well. The method returns true if otherBag and the bag that activates the method have exactly the same number of every element. Otherwise the method return false. Note that the locations of the elements in the data arrays are not necessarily the same, it is only the number of occurrences of each element that must be the same. (3) Implement a static method, called sumEven, in the IntArrayBag class that takes one input parameter of type IntArrayBag. The method then calculates and returns the sum of all even elements in the bag. (4) Re-implement the static sumEven method, in the IntArrayBag class that takes one input parameter of type IntArrayBag. The method then calculates and returns the sum of all even elements in the bag.
Consider the IntArrayBag data structure that is represented by the following UML. IntArrayBag -data:int[] -manyltems:int +IntArrayBag() +IntArrayBag(capacity:int) +add(element:int):void +countOcuurances(target:int):int +grab(index:i):int +remove(target:int):void +size():int +max():int +countEven():int +change(oldVal:int, newVal:int):int (1) Implement an instance method, called bagMax, in the IntArrayBag class that finds and return the maximum value in the bag. (2) Implement an instance method, called equals To, in the IntArrayBag's class that takes one input parameter and returns a boolean value. The input parameter, called otherBag, is of type IntArrayBag as well. The method returns true if otherBag and the bag that activates the method have exactly the same number of every element. Otherwise the method return false. Note that the locations of the elements in the data arrays are not necessarily the same, it is only the number of occurrences of each element that must be the same. (3) Implement a static method, called sumEven, in the IntArrayBag class that takes one input parameter of type IntArrayBag. The method then calculates and returns the sum of all even elements in the bag. (4) Re-implement the static sumEven method, in the IntArrayBag class that takes one input parameter of type IntArrayBag. The method then calculates and returns the sum of all even elements in the bag.
New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter14: Exploring Object-based Programming: Designing An Online Poker
Section14.1: Visual Overview: Custom Objects, Properties, And Methods
Problem 7QC
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning