String Methods
Arrays
Classes
ArrayLists
2D Arrays
100

str2.indexOf("s");

4
100

What is at arr4[arr4.length-1]?

4

100

The 'Book' class has instance variables 'title', 'author', and pages with constructor header shown below:

public Book(String title, String author, int pages)

{ /*Implementation not shown */ }

Write a line of code that constructs a 'Book' object in main and stores it in a new object variable.

Book gatsby = new Book("The Great Gatsby", "F. Scott Fitzgerald", 192);

100

arrList1.add(14);

arrList1.add(18);

arrList1.remove(0);

What is in arrList1?

[5, 8, 10, 14, 18]

100

System.out.print(twoDArray2[1][0]);

What will print?

2

200

Will str4.compareTo(str1) return a value that is greater than or less than 0?

Greater than 0

200

cakes[2] = cake15;

cakes[1] = cakes[0];

What is in cakes?

[cake1, cake1, cake15, cake12]

200

Write a constructor definition for a 'Song' class which connects the instance variables 'title', 'artist', and 'track' to the parameters of the constructor header.

public Song(String title, String artist, int track) {

this.title = title;

this.artist = artist;

this.track = track;

}

200

System.out.print(arrList2.get(1) + " " + arrList2.get(0) + " " + arrList2.get(arrList2.size()-1));

What will print?

you my us

200

for(int r = 0; r<twoDArr1.length; r++){

for(int c = 0; c<twoDArr1[0].length; c++){

System.out.print(twoDArr1[r][c] + " ");

}

}

What will print?

Five Four Three Two One Zero

300

String str5 = str4.substring(6, 11);

What is str5?

he Ja

300

for(int i =0; i<arr1.length; i++){

if(arr1[i] >= 2.0){

System.out.print(arr1[i])+" "; }

}  

What will print?

2.5 7.8 9.3

300

Write a constructor for the Teacher class, which takes in a 1D array of strings called "classes" and a 2D array of integers called "grades" and stores them in appropriate instance variables.

public Teacher(String[] classes, int[][] grades) {

this.classes = classes;

this.grades = grades;

}


300

Write a command to place the value of 5.5 at the very beginning of arrList4 so that it replaces 8.6.

arrList4.remove(0);

arrList4.add(0, 5.5);

OR 

arrList4.set(0, 5.5);

300

Double sum = twoDArr3[1][2] + twoDArr3[0][3] + twoDArr3[2][3];

24.7 

(2.2 + 10.2 + 12.3)

400

String str6 = str2.substring(4);

What is str6?

scored a 5!
400

arr3[0] = arr3[arr3.length-1]

arr3[1] = arr3[arr3.length-2]

What is in arr3?

[false, true, true, true, false]

400

Write a 'Circle' class with appropriate instance variables for an x-coordinate, y coordinate, and radius. Include the constructor definition as well.

public class Circle {

    private int xCoord;

    private int yCoord;

    private int radius;

public Circle(int xCoord, int yCoord, int rad) { 

     this.xCoord = xCoord;     //etc.

    }

}

400

int num = arrList1.size() + arrList2.size() - arrList3.size();

What is num?

6

400

for(int c = 0; c<twoDArr2[0].length; c++){

for(int r = 0; r<twoDArr2.length; r++){

System.out.print(twoDArr2[r][c] + " ");

} System.out.println();

}

5 2

5 2

6 6

7 0

9 12

500

String str7 = str1.substring(10,str1.length()-1) + str3.substring(0,3);

What is str7?

jobFRQ

500

Which two arrays would be appropriate for a binary search (disregarding the length of the arrays)?

arr2, arr4

500

The Math class includes a static method called random().  Write the command that will generate a random number to select one of the months of the year (from 1 to 12).

Math.random()*12 +1;

500

Write the commands that will change arrList2 to contain ["I", "me", "my", "you", "we", "us"]

arrList2.add(0, "me");

arrList2.add(0, "I");

500

for(int r = twoDArr3.length-1; r>=0; r--){

for(int c = twoDArr3[0].length-1; c>=0; c--){

System.out.print(twoDArr3[r][c] + " ");

} System.out.println();

}

12.3 18.8 16.5 11.5 

10.4 2.2 4.5 9.6

10.2 9.4 8.4 7.5

M
e
n
u