30 likes | 149 Views
SEEM3460 Tutorial. Arrays in Java. Arrays in Java. Initialization array1 = new SomeClass [ARRAY_SIZE]; array1 = {element1, element2, …}; Object as elements Example: Tunes.java + CDCollection.java + CD.java Array as parameter public void SomeMethod ( int [] arr ) {…}
E N D
SEEM3460 Tutorial Arrays in Java
Arrays in Java • Initialization • array1 = newSomeClass[ARRAY_SIZE]; • array1 = {element1, element2, …}; • Object as elements • Example: Tunes.java + CDCollection.java + CD.java • Array as parameter • public void SomeMethod(int[] arr) {…} • Use System.arraycopy() and .length
Exercise • Create an extra CD constructor for “Empty” • Create a class CDShelf with: • an integer variable called “rowcount” • an integer variable called “rowsize” • a two-dimensional array for holding “rowsize”x“rowcount” CDs • a constructor to fill shelf with “Empty” • a method to list all CDs of a row • a method to list all CDs of the shelf • a method to insert CD to specific position • a method to replace a row of CDs • a method to calculate row total price • a method to calculate shelf total price