/** * Author: Josiah Yoder et al. * User: yoder * Class: SE1011-011 * Lesson: Week 9, Day 3 */ import java.util.ArrayList; import java.util.Scanner; public class Example011_10_2 { public static void main(String[] ignored) { /* Design strategies Top-down Bottom-up Case-based */ /* Reasons for using an ArrayList Store objects Change length of array Variable-size Matrices Reasons for using an Array Storing primitive types Large matrix of primitive types */ int x = 0; int y = 0; x++; y = x; // doesn't work //ArrayList list = new ArrayList(); // doesn't work ArrayList list = new ArrayList(); // FROM LAST CLASS // Arrays // Lines up side-by-side with ArrayLists below Complex011_10_2[] complexArray; complexArray = new Complex011_10_2[5]; complexArray[0] = new Complex011_10_2(1,2); for(int i=0; i complexArrayList; complexArrayList = new ArrayList(); //complexArrayList.set(0, // new Complex011_10_2(1,2)); complexArrayList.add( new Complex011_10_2(1,2)); // complexArrayList.remove(0); for(int i=0; i 0.00001 // Solution: Thanks to the class for help in writing this double real; double imag; Scanner in = new Scanner(System.in); ArrayList list1 = new ArrayList(); do { System.out.println("Enter the real component: "); real = in.nextDouble(); System.out.println("Enter the imaginary component: "); imag = in.nextDouble(); if( real != 0 || imag != 0 ){ list1.add(new Complex011_10_2(real, imag)); } } while (real !=0 || imag !=0); ArrayList list2 = list1; // Draw what this looks like in memory } }