Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4. The following two questions use the same Item class that we saw earlier, where each item has a name and value. The definition of
4. The following two questions use the same Item class that we saw earlier, where each item has a name and value. The definition of the Item class is shown below. public class Item { private String name; private int value; public Item(String itemName, int itemValue) { name = itemName; value = itemValue; } public String getName() { return name; } public int getValue() { return value; } } a. Write a method public static int range (Item [] [] grid) that takes a 2D array of properly instantiated Item objects as a parameter and returns the difference between the largest value and the smallest value among all the Item objects in that array. For example, if the largest value among the items in the array is 25, and the smallest value among the items in the array is 10, this method should return 15. b. Write a method public static int numEqual (Item [] [] grid) that takes a 2D array of properly instantiated Item objects as a parameter and returns the total number of those items whose value is equal to the length of its name. For example, if a certain Item in grid has a value of 5 and its name is "grape", which has five letters, that would count towards the total
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started