SEEM3460 Tutorial
Download
Report
Transcript SEEM3460 Tutorial
SEEM3460 Tutorial
Arrays in Java
Arrays in Java
Initialization
Object as elements
array1 = new SomeClass[ARRAY_SIZE];
array1 = {element1, element2, …};
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