Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please Solve this by Java 14 Question 3 (10 points) - Capacity 10 Assume you have a class called MyObject. Complete the capacity method below
Please Solve this by Java
14 Question 3 (10 points) - Capacity 10 Assume you have a class called MyObject. Complete the capacity method below to provide information about the current capacity of a given 2D array of MyObjects. The method should return an array of two ints, where the first is the number of objects filled in the array, and the second is the total number of objects that can fit in the array. You may assume the 2D array and its component arrays (because a 2D array is an array of arrays) are all initialized, but the 2D array may be ragged. Hint: A spot in a 2D array is not "filled" if there is no object assigned to that location, so if its value equals (--) null. public static int[] capacity (MyObject[][] arr) { int[] capInfo = new int[2]; } return capInfo; // For example: calls to capacity method (and the results returned) public static void main(String[] args) { MyObject[] [] arr1 = new MyObject [3] [4]; int[] capacityInfo capacity (arrl); System.out.println("arrl is at " + capacityInfo [0] + "/" + capacityInfo [1] + " capacity"); // prints "arrl is at 0/12 capacity" MyObject[] [] arr2 = new MyObject [2] []; arr2[0] = new MyObject[] {new MyObject() }; arr2[1] = new MyObject [5]; capacityInfo capacity (arr2); System.out.println("arr2 is at " + capacityInfo [0] + "/" + capacityInfo [1] + " capacity"); // prints "arr2 is at 1/6 capacity" }
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