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
icon
Related questions
Question
100% +
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 equalsTo, 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.
Transcribed Image Text:100% + 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 equalsTo, 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.
2 / 2
100% +| E O
Consider the IntArraySequence data structure that is represented by the following UML.
IntArraySequence
-data:int[]
-manyltems:int
-currentIndex:int
+start():void
+advance():void
+getCurrent():int
+addAfter(element:int):void
+addBefore(element:int):void
+removeCurrent():void
+size():int
(1) Implement an instance method, called reverse, in the IntArraySequence class that
returns another sequence as output where the output sequence has the same elements
as the input sequence but in reverse order. For example, if the input sequence contains
the numbers {10,20,30,40}, then output sequence will contain (40,30,20,10}. You can use
any of the methods listed in the above UML.
(2) Assume that two sequences are considered equal is they contain the same values in the
same order. Implement a static method outside the IntArraySequence called
equalSeqeunces that takes two IntArraySequence parameters as input and
returns true or false based on whether the two input sequences are equal or no. You
can use any of the methods listed in the above UML.
Transcribed Image Text:2 / 2 100% +| E O Consider the IntArraySequence data structure that is represented by the following UML. IntArraySequence -data:int[] -manyltems:int -currentIndex:int +start():void +advance():void +getCurrent():int +addAfter(element:int):void +addBefore(element:int):void +removeCurrent():void +size():int (1) Implement an instance method, called reverse, in the IntArraySequence class that returns another sequence as output where the output sequence has the same elements as the input sequence but in reverse order. For example, if the input sequence contains the numbers {10,20,30,40}, then output sequence will contain (40,30,20,10}. You can use any of the methods listed in the above UML. (2) Assume that two sequences are considered equal is they contain the same values in the same order. Implement a static method outside the IntArraySequence called equalSeqeunces that takes two IntArraySequence parameters as input and returns true or false based on whether the two input sequences are equal or no. You can use any of the methods listed in the above UML.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning