The method to create an object
What is a Constructor
Keyword to create an object
What is new
What is the value of this arrayList:
ArrayList<Student> students;
What is null
Find the index of the letter "e" in a String variable called word after the 4th letter. Store it in a variable called spot
What is
int spot = word.indexOf("e", 3);
The import statement to use an ArrayList
Access Modifier for an instance variable
What is private
Create an object of type Device called computer that calls a constructor with one parameter a String that holds the value laptop
What is
Device computer = new Device("laptop");
Create an empty ArrayList of type Bottle called bottles
What is
ArrayList<Bottle> bottles = new ArrayList<Bottle>();
Loop through a String using an Enhanced Loop to build a new String that is the reverse of the original String
What is
String reverse = "";
for(Character letter : word){
reverse = letter + reverse;
}
What are instance variables, constructors, getters, setters, other private methods, toString
The last method for every class
What is toString
You have an object called student1 in the main method of a Driver class. Print out the name of the student. Assume all getters are made.
What is
System.out.println(student1.getName());
Loop through a list called buildings of type Building and print each building out. Use an Enhanced Loop
What is
for (Building b : buildings){
System.out.println(b);
}
The kind of value return by this line of code:
word1 = "Bat";
word2 = "bat";
word1.compareTo(word2);
What is a negative number
The difference between to two remove methods for an ArrayList
What is one removes at an index and returns the object. The other one removes the object and returns true or false.
The header for the final method in a class
What is
@Override
public String toString()
You have a Car object that has an instance variable of type Wheel. The Wheel class has a getType method. Write a line of code to get the type of wheel that car1 has and store it.
What is
String wheelType = car1.getWheel().getType();
Get the 3rd person object in the list called people and change the name to be John. Assume all setter methods are made
What is names.get(2).setName("John");
What is printed?
int outer = 1;
int total = 0;
while (outer <= 3) {
int inner = 1;
while (inner <= 2) {
total += outer * inner;
inner++;
}
outer++;
}
System.out.println("Final total: " + total);
What is 18
Print the last item in the items list but first make sure two things are true.
if(items != null && items.size()>0){
System.out.print(items.get(items.size()-1));
}
The word this is used for
What is to differentiate the instance variable from the parameter value
Write a method to see if two Animal objects are both the same species
What is
public boolean sameSpecies (Animal other){
return this.species.equals(other.species);
}
Use a loop to remove all movie objects that are inTheaters. They are in a list called movies
What is
for (int i = movies.size()-1; i >=0; i--){
if(movies.get(i).isInTheaters()){
movies.remove(i);
}
}
What does this print?
String phrase = "AbC";
String output = "";
int pos = 0;
while (pos < phrase.length()) {
String current = phrase.substring(pos, pos + 1);
int count = 0;
while (count < 2) {
if (current.equals(current.toUpperCase())) {
output += current.toLowerCase();
} else {
output += current.toUpperCase();
}
if (phrase.indexOf(current) % 2 == 0) {
output += count;
}
count++;
}
pos++;
}
System.out.println("Final output: " + output);
What is a0a1BBc0c1
import java.util.ArrayList;
ArrayList<Integer> nums = new ArrayList<Integer>();
nums.add(2);
nums.add(4);
nums.add(3);
nums.add(7);
int i = 0;
while (i < nums.size()) {
if (nums.get(i) % 2 == 0) {
nums.set(i, nums.get(i) / 2);
} else {
nums.remove(i);
i--;
}
i++;
}
System.out.println("Final list: " + nums);
What is
Final List: [1,2]