CS100M Spring 2004 Lab 12 (combined with Lab 13 and "Lab 14"): Arrays, Sorting Worth the equivalent of 3 labs! Due Sunday 5/9 23:59 TAs will cover (0), (1), and (3). (2) you might need to do on your own afterwards. 0) Do you have any questions about arrays? - syntax for 1-D? - syntax for 2-D? - declaration statement? - what's the $.length$ field? - how to write for loops for 1-D? 2-D? - what's an initializer list? 1) OK, let's see if you know most everything in (0) Write a program Task1.java that creates a rectangular 2-D array of random integers. The size of the array and range of integers is input via the command line. The program will output the array. For example, input: > java Task1 2 3 0 1 output: 1 0 0 0 1 0 You don't have to do error checking on the inputs. Writing separate methods for creating, filling, and printing the arrays will make your life easier and code much cleaner. If you cannot do this example very quickly, make sure you practice until you can. 2) Arrays of Objects Write a program Task2.java that + creates a square array of random Complex (3x3) (OK to use ints) + creates 1-D array of random Complex numbers (3 elements) (OK to use ints) + multiplies the array by the "column vector" + outputs the result as a column Reminder about matrix-vector multiplication: [A11 A12 A13] {x} {A11*x+A12*y+A13*z} A*v -> [A21 A22 A23] {y} -> {A21*x+A22*y+A23*z} [A31 A32 A33] {z} {A31*x+A32*y+A33*z} Feel free to use previous work, but make sure your Complex arithmetic functions are correct!!! In comment statements, show the MATLAB code that does the exact work. (You *do* have MATLAB coming up on the final exam....) In more comment statements, show how you tested your code for correctness. 3) Sorting You will need to write a program that sorts Complex numbers. Things to note: + How do you compare a Complex number to another? Try a few values in MATLAB. + How do you sort objects? Refer to the simplifed $compareTo$ methods from previous labs and homework. You can be fancy if you use the Comparable interface from java.lang. + Gather your previous work with Complex numbers. + Track down the bonus solution of Lab 9 Write a program called Task3.java that creates a random array of Complex numbers for a user-input length. You can decide on the range of real and imaginary values (OK to use ints). Write two class methods for Task3: (1) public static Complex[] selectSortUp(Complex[] c) This method will sort the input array in ascending order and return the sorted array. You must use the select sort algorithm! (2) public static Complex[] selectSortDown(Complex[] c) This method will sort the input array in descending order and return the sorted array. You must use the select sort algorithm! (3) public static Complex[] insertSortUp(Complex[] c) This method will sort the input array in ascending order and return the sorted array. You must use the insert sort algorithm! See Problem 5 on pg. 412 of Savitch. Note that you need to preserve a copy of the array because you will need to demonstrate how to sort it three different ways. In all three subtasks, you must output the sorted array to demonstrate the accuracy of your code. 4) Inheritance Task 5: Write a collection of classes and a driver program that defines a hierarchy of shapes, with the highest superclass as an abstract class Shape with abstract method area that returns the area of a shape. In the hierarchy, develop classes for Ellipse, Circle, Rectangle, Quadrilateral, Trapezoid, Rhombus, and Square. Test each type of shape in your Main Class by creating an object of each and printing its area. 5) Zip your code together in e12.zip and submit on CMS. Do not wait for the last minute, as a few people have done lately. They weren't able to submit their work on time....