30 likes | 160 Vues
This tutorial explores Java arrays and their initialization techniques, including the use of specific examples like Tunes.java, CDCollection.java, and CD.java. Learn how to pass arrays as parameters in methods, utilize System.arraycopy, and implement exercises focused on array length. You'll also create a CD constructor for “Empty” entries, design a CDShelf class with dynamic row and column integer variables, and develop methods to manage CDs effectively—listing, inserting, replacing, and calculating prices. Gain a solid understanding of Java arrays and object-oriented principles.
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