//A2 extented to Monday Noon int[] a; int[] b; a b a == b a = new int[]{1,2,3}; int[] c = a; c int[] d={1,2,3}; int[] e={1,2,3}; e==f //let's write equals method for two int arrays //equal: if they are both null, or both have the same length and elemetns int[] b; int[] c = {65,42}; ArrayDemo.equals(b, c) int[] d = {65, 42} c==d ArrayDemo.equals( c,d) int[] a1 ={1,2,3} int[] a2 = ArrayDemo.copyArray(a1, 3); a1 a1 == a2 ArrayDemo.equals( a1, a2) //swaping two elements in an array: int [] a = {0, 1, 2, 3, 4, 5} a[1] a[4] //let's swap a[1] and a[4]: int tmp = a[1] a[1] = a[4] a[4] = tmp ArrayDemo.displayArray(a, 0 , 5) //let's write a swap method ArrayDemo.swap(new int[]{1,2,3}, 0, 2) int[] a3={1,2,3}; int[] a4= ArrayDemo.swap(a3, 0, 2) ArrayDemo.displayArray(a4, 0, 2)) ArrayDemo.displayArray(a3, 0, 2)) //what? a3 has changed as well! a3 a4 a3 == a4 //a3 and a4 are the same object, why? //look at swap, it does swap "in place" without creating a new array so it return the original pointer. //Exercise: change swap such that it doesn't change the original array, and return the result as a new array Pizza p = new Pizza(3, "large"); p.addTopping("pineapple") p.addTopping("pineapple") p.addTopping("ham") p.addTopping("extra cheese") Pizza p2 = new Pizza(3, "small"); p.addTopping("extra cheese") p.addTopping("ham") p.addTopping("pineapple") p.addTopping("pineapple")