Question: Lab #1 Go to Java Online Compiler (Click it). Copy all provided code and requirements below. Finish all TODOs and test your code at the
Lab #1
Go to Java Online Compiler (Click it). Copy all provided code and requirements below. Finish all TODOs and test your code at the online compiler. Do NOT modify any provided code. IMPORTANT When completed, copy all code back to the box below for submission.
//A provided class representing triangle, do NOT modify it class Triangle { private double base, height; public Triangle(double base, double height) { this.base = base; this.height = height; } public double getArea() { return 0.5 * base * height; } @Override public String toString() { return "Triangle(" + base + ", " + height + ")"; } }
public class Main { public static void main(String[] args) { System.out.println(getBigTriangle(null)); //Expected Output: null System.out.println(getBigTriangle(new Triangle[0])); //Expected Output: null System.out.println(getBigTriangle(new Triangle[]{null, null})); //Expected Output: null
/* ==== Do NOT modify any code above this line ==== */
/** * TODO #1: create an array containing the following 5 triangles: * (Base, Height) = (2.3, 1.2), (4.5, 2.7), (3.2, 1.9), (5.8, 3.4), (1.5, 0.7) * Then use this array to call the getBigTriangle method defined in TODO #2. Print the returned value. * Expected Output: Triangle(5.8, 3.4) */
}
/** * TODO #2: write a public static method named getBigTriangle that * - accepts an array of triangles as the argument * - returns the triangle of the largest area, or * returns null if there is nothing to return * - Note: The argument array may be null or empty. * - Note: The elements in the array may be null. */
} // 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
