Java Questions 3

Ace your homework & exams now with Quizwiz!

A ___________ is a special method that creates new objects.

constructor

To ____ a method is to invoke a method or cause it to execute.

call

A _____ is a set of objects; every object belongs to one of these.

class

A collection of related methods is called a

class

This code is supposed to print the equivalent hours, minutes and seconds of a certain number of seconds. Fill in the blank. int sec = 19341; int hour = sec / 3600; int remainingSec = sec % 3600; int min = remainingSec / 60; remainingSec = ________________ System.out.println ( sec + " sec = " + hr + ":" + min + ":" + remainingSec);

remainingSec % 60

After the statements in the last problem finish, where will bizzy be?

3,7

In a function expression such as sin(3*angle) the content inside the parentheses is called the:

Arguement

The Java compiler generates:

Byte code

Write a statement to create a new Flower and store it in a variable of type Flower called petunia:

Flower petunia = new Flower();

A statement that declares a new variable and assigns a value to it at the same time, such as int x = 4; is called an ______________.

Initialization

What does JVM stand for?

Java Virtual Machine

A ______ is a named sequence of statements that performs a useful function. They may or may not take parameters, and may or may not return a value.

Method

What will the following program print? (Hint: Recursion) public static void message(int n) { if (n <= 0) { System.out.print("Zip"); } else if (n == 1) { System.out.print("Uno"); } else { System.out.print("Tre"); message( n - 2 ); } } public static void main(String [] args) { message(1); message(2); message(5); }

UnoTreZipTreTreUno

A named storage location in memory that contains a value is known as a:

Variable

A condition that causes a recursive method NOT to make a recursive cal1 is known as the:

base case

Variables of type ______ can store values that are whole numbers, like 4 or -38.

int

What is the output of this program? x = 23; if (x > 0) { if (x < 20) { System.out.print("Fine!"); } else { System.out.print("Oky-doky."); } System.out.print("Huh?"); } else { System.out.print("mm-hmm"); } System.out.println("Oh");

Oky-doky.Huh?Oh

In the following program there is one error. The word ______ should be replaced with the word int. String hour, minute; hour = 11; minute = 59; System.out.print("Number of minutes since midnight: "); System.out.println(hour*60 + minute); System.out.print("Percent of hour that has passed: "); System.out.println(minute*100/60);

String

Variables of type ______ can store values that are sequences of letters.

String

These are the rules (grammer) that must be followed when writing a program:

Syntax

The following code has an error. Find the line with the error and type the corrected version of that line. if (x < 70) { System.out.println("D or lower"); } else if (x < 80) { System.out.println("C"); } else (x >= 80) { System.out.println("B or higher"); }

else (x >= 80) {

What is printed by the following program? String sal; sal = "timbers"; String yada; yada = "shiver"; System.out.print("Well, "); System.out.print(yada); System.out.print(" me "); System.out.print(sal); System.out.println("!");

Well, shiver me timbers!

An ________ method is a method that returns an attribute of an object, for example getColor() or getDirection()

accessor

Variables of this data type can hold floating-point values such as 4.321 and -3.14159 :

double

Which Java statement declares variable hyp and assigns it the square root of variable sidesq?

double hyp = Math.sqrt( sidesq );

An object is also called an ________ because it is a member, or ________, of a class. (Both blanks are the same word. What is it?)

instance

This type of error refers to a mistake in the meaning of your program (the program doesn't do what it's supposed to do):

logic error

Which Java statement takes the square root of the square root of 2401 and assigns the result to variable lucky (which has already been declared)?

lucky = Math.sqrt( Math.sqrt(2401));

What is the output of this program? x = -5; if (x > 0) { if (x < 20) { System.out.print("Fine!"); } else { System.out.print("Oky-doky."); } System.out.print("Huh?"); } else { System.out.print("mm-hmm"); } System.out.println("Oh");

mm-hmmOh

A ________ method changes an attribute of an object, for example, moveTo() or setDirection()

modifier

This operator computes the remainder of a division, in Java and C++, represented by the % sign.

modulus

The components of GridWorld, including Bugs, Rocks and the Grid itself, are all called _______.

objects

A piece of information a method requires before it can run is called a _________. These are a kind of variable: they contain values and have types.

parameter

An operator that converts from one type to another. In Java it appears as a type name in parentheses, like (int).

typecast

In the following program we declare seven variables and assign values to them. What is printed by the following program? double a, b, c ; int d, e, f, g ; a = 3.5 ; b = 9.0 / 2.0 ; c = 5 / 3; d = 2 * 3 ; e = 14 / 3; f = (int) (b * e); g = (int) b * e; System.out.println(a + ", " + b + ", " + c + ", " + d + ", " + e + ", " + f + ", " + g);

3.5, 4.5, 1.0, 6, 4, 18, 16

For the following GridWorld program, fill in the blank to make bizzy face East ActorWorld world = new ActorWorld(); Bug bizzy = new Bug(); world.add(bizzy); bizzy.moveTo(new Location(3,5)); bizzy.setDirection(__); // turn bizzy to face East bizzy.move(); bizzy.move();

90

The following java code prints a message to the screen. What does it say? System.out.print("A"); System.out.print(" Super"); System.out.println("-->Cat!");

A Super-->Cat!

Recall the method vertLineOfRocks() from assignment 5, public static void vertRockLine(ActorWorld world, int row, int col, int numRocks) { if (numRocks > 0){ Rock p = new Rock(); world.add(p); p.moveTo( new Location(row,col)); vertRockLine(world, row-1, col, numRocks - 1); } }

vertRockLine(world,8,3,7);

The following code should assign 100 to x when y is equal to 0. Fill in the blank if (______) { x = 100; }

y == 0

The following code should assign 0 to x when y is greater than or equal to 10. Otherwise it should assign 1 to x. Fill in the blank. if (_____) { x = 0; } else { x = 1; }

y >= 10


Related study sets

Module 13: Alterations of Renal and Urinary Tract Function

View Set

Chapters 1,2,3,4,11 reading quiz

View Set

Chapter 9 Vocabulary Human A & P

View Set

Environmental Science - Chapter 11 Test 2

View Set

10.16.4 Main Ideas, Topic Sentences, and Thesis Statements

View Set

Chapter 18: Advertising and Public Relations

View Set

Computer Science - Term one half one- ALgorithims

View Set