Question: import java.util.*; //A provided class representing cube, do NOT modify it class Cube { private int length, width, height; public Cube(int length, int width, int
import java.util.*;
//A provided class representing cube, do NOT modify it class Cube { private int length, width, height; public Cube(int length, int width, int height) { this.length = length; this.width = width; this.height = height; } public int getVolume() { return length * width * height; } @Override public String toString() { return "Cube(" + length + "," + width + "," + height + ")"; } }
public class Midterm_Main2 { public static void main(String[] args) { //Expected Output: //>>1. Big cubes: null //>>2. Big cubes: null //>>3. Big cubes: [Cube(4,5,6), Cube(5,6,7), Cube(6,7,8)] //>>4. Big cubes: null System.out.println(">>1. Big cubes: " + getBigCubes(null, 100)); System.out.println(">>2. Big cubes: " + getBigCubes(new Cube[0], 100)); Cube[] cubes1 = { new Cube(3, 4, 5), new Cube(4, 5, 6), null, new Cube(5, 6, 7), new Cube(6, 7, 8), new Cube(2, 5, 8), null, new Cube(1, 4, 7)}; System.out.println(">>3. Big cubes: " + Arrays.toString(getBigCubes(cubes1, 100))); Cube[] cubes2 = { null, new Cube(1, 1, 1), null, new Cube(1, 1, 1) }; System.out.println(">>4. Big cubes: " + Arrays.toString(getBigCubes(cubes2, 100))); }
/* ==== Do NOT modify any code above this line ==== */
/** * + TODO #1: write a public static method named getBigCubes that * - accepts two arguments, an array of cubes and an int minVolume * - returns a new array containing all big cubes that have volume * not less than the given minVolume, or * - returns null if there is nothing to return * - NOTE: the given array can be null or of length zero * - NOTE: elements in the given array can be null * - NOTE: do NOT modify the given array argument */ } // End of Main class
// IMPORTANT: When completed, copy all code back to the text box in the quiz for submission. //----------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
