/*A1: * read your email carefully, before asking questions! I you really need remark request, you need to fill out appropriate form avaialbe on the website * Jie Hao : your utoronto.ca email boucned back!! * If your A1 mark is not posted on the portal system, you have to come and see me (there is a problem that if not resolved, you will be given 0). Important A2 Issue: To help you: we will mark shoppingcart and creditcard classes separately. it is important to use correct method names, no extra public method (other than those mentiond in the handout) otherwise won't comile will lead to getting 0!! So, make sure all your *helper methods* are private. Lab feedback: TAs complain many students don't finish them! This is not good! Leads to problem with assignments and final exam!!! */ //we have talked about various Control strutures: sequence, conditional, and loop //we have also talked about Data structures: privmitive data types and classes //A very useful data structure for holding data is array //Arrays can strore many elements of the same type (0, 1, or even 1000000) //you can create them on the fly, for example, in the Band class, we // might want to have different number of musician 1,2 ,3, or even 20 //instead of declaring 20 Musician variables, we just define 1 Musicain[] varaib le that holds the appropriate number of musicians //Also there are situations we don't know in advance how many elements //we need (e.g. the user may tell us) so we cannot declare that many varaibles //in our code in advance!! int x = 7; int y = 3; int[] a; // declare a to be an integer array a a = new int[3]; a a[0] a[1] a[2] a[3] a[0] = 3; a[0] a[1] = 4; a[2] = 2; a[1] = "TEST"; //what's the problem. a[1] a[3] //problem? a.length a.length() a.length // a public variable a.length = 7; a.length = 7; // can't reassign it: it's "final" // int[] read it as "integer array" or "array of ints" // a is an integer array with 3 elements int[] b = new int[]{5, 12, 7}; b[0] b[1] b[2] //syntax suger: also ok to say the following (it will autmatically new the space required and initialize the array) int[] b2 = {2, 3, 5, 9, 234} b2.length b[4] //elements of array can be objects (but all of the same type). //let' create an array of JFrame (compare to array of int) import javax.swing.JFrame; JFrame[] j = new JFrame[4]; j j[2] //as you can see after newing the array, all elements get their default value, for object it's null) j[2] = new JFrame(); j[2] j[0] j[1] j[3] j[2].setVisible(true); j[2].setTitle("Element at position 2"); //let's create an array of 2 JFrames and initilize it at the same time (see how we did this with int arrays) JFrame j2 = new JFrame[]{new JFrame(), new JFrame()}; //oops! JFrame[] j2 = new JFrame[]{new JFrame(), new JFrame()}; //also could have use the short hand: JFrame[] j2 = {new JFrame(), new JFrame()}; j2[0].setVisible(true); j2[1].setVisible(true);