A Classy Category
Logic, logic, and MORE logic!
Cookin' up methods!
Staying under control
Algorithms 4 Life
100

This is the method that is called in main to instantiate an object.

What is a constructor?

100

Write the basic truth table one would use to test conditional statements that include two boolean statements A and B.

What is  A   B  

             T   T

             T   F

             F   T

              F   F ?

100

It's the two main types of methods featured here:

public void setPaint(int num)

public String toString()

What are void methods and return methods?

100

This is the for loop header one would need to print the numbers 1 to 100 inclusive.

What is for (int i = 1; i <= 100; i++) ?

100

This would be the result of example 1 if num1 were initialized with a value of 4 and num2 were initialized with a value of 7.

What is -8?

200

A UML diagram is a graphic organizer where one can fill in the attributes and behaviors available in a class. "Attributes" represent these in the class file, and "behaviors" represent these.

What are instance variables and methods?

200

It's the truth table that results from the following expression:

A || !A

What is "all values are true"?

200

Write the method called addTip that would print the payment amount based on two parameters: the cost of the meal and the desired tip amount.

What is public void addTip(double total, double tipAmount) {

System.out.print(total + tipAmount); }

200

Assume int count and boolean hasMore have been properly declared and initialized. This is the while loop one would need to iterate so long as count is less than 50 and hasMore is true.

What is while (count < 50 && hasMore == true) ?

200

This would be the result in example 2 if a were initialized with a value of 10.

What is 9 29.5 32.0?

300

For the following class, it's the line that would replace <missing code> to set the instance variable equal to the constructor parameter:

public class Soda {

   private int gramsSugar;

   public Soda(int g) { 

   <missing code> 

   }

}

What is gramsSugar = g;?

300

It's the final value of grade when score = 90.

String grade = "";

if (score >= 60) grade += "D";
if (score >= 70) grade += "C";
if (score >= 80) grade += "B";
if (score >= 90) grade += "A";
else grade = "E";

What is "DCBA"?

300

What is the method header for a method called check that takes two integers and returns a true or false value based on its calculations?

What is 

public boolean check (int x, int y)

300

Write a nested for loop that will iterate a total of 15 times.

What is for(int i = 0; i < 5; i++) {

            for(int j = 0; j < 3; j++) {

}

}

300

Look at example 3. This line would replace <missing code2> if <missing code1> were int area = w * l; 

What is int vol = area * h; ?

400

It's the error seen here:

Book firstBook = Book("IT", "Stephen King");

What is a missing "new" keyword?

400

De Morgan's law states it is equivalent to this boolean expression:

!(num>10 || num!=50)

What is num<=10 && num==50?

400

When printing an object, the Java compiler automatically calls this special method to determine what to print.

What is toString()?

400

Write a for loop (header only) to traverse a String object called word.

What is for (int i = 0; i < word.length(); i++) ?

400

These would be the three method headers in example 4 to return the values of the instance variables in the Team class so that they can be used in a class other than Team.

What are public String getTeamName(), public int getNumPlayers(), public double getWinPercentage()?

500

Class files typically begin with declaring private instance variables.  This keyword can be added to an instance variable in order to make it accessible by all objects of that class.

What is static?

500

It's the result of the following when num = 15 and num2 = 3:

if(num > 10) {

  if((num + num2) % 2 == 1) {

     System.out.print("Yay!");

  { else }

     System.out.print("Boo!"); 

   }

}

What is Boo!

500

Write the class header, instance variables, and parameterized constructor (header only) in the Movie class file based on the following constructor call:

Movie newMovie = new Movie("Scream", "R");

What is public class Movie {

   private String title;

   private String rating;

public Movie(String title, String rating) {?

500

Convert the following for loop into a while loop:

for(int i = 0; i < 300; i += 10) {

   System.out.println("The number is " + i);

}

What is 

int i = 0;

while(i < 300) {

System.out.println("The number is " + i);

i += 10;

}  

500

This would print in example 5 if num were initialized with a value of 3.

What is 3 9 10 20?