Friday, May 6, 2011

chapter 3

What would be the value of discountRate after the following statements are executed?

double discountRate = 0.0;
int purchase = 100;
if (purchase > 1000)
discountRate = .05;
else if (purchase > 750)
discountRate = .03;
else if (purchase > 500)
discountRate = .01;

===Cannot tell from code

Which of the following will format 12.78 to display as 12.8%?
==##0.0%

What does the following code display?

int d = 9, e = 12;
System.out.printf("%d %d\n", d, e);

===9 12

Which of the following correctly tests the char variable chr to determine whether it is not equal to the character B?
==if (chr != 'B')

This is a boolean variable that signals when some condition exists in the program
==Flag

The expression in an if statement must evaluate to
==true or false

A local variable's scope always ends at the closing brace of the block of code in which it is declared.
==true

Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression most likely false expression is on the left.
==true

If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal?

(1) (str1 == str2)
(2) str1.equals(str2)
(3) (str1.compareTo(str2) == 0)
===2 and 3

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?
==((x > 500 && x < 650) || (y != 1000))


What would be the value of discountRate after the following statements are executed?

double discountRate = 0.0;
int purchase = 1250;
if (purchase > 1000)
discountRate = .05;
if (purchase > 750)
discountRate = .03;
if (purchase > 500)
discountRate = .01;
else
discountRate = 0

===0.01

A flag may have the values
==true or false

What does the following code display?

double x = 12.3798146;
System.out.printf("%.2f\n", x);
==12.38

What is the value of ans after the following code has been executed?

int x = 35;
int y = 20, ans = 80;
if (x < y);
ans += y;
==100


Because the || operator performs short-circuit evaluation, your boolean statement will generally run faster if the subexpression that is most likely to be true is on the left.
==true

What would be the value of bonus after the following statements are executed?

int bonus, sales = 85000;
char dept = 'S';
if (sales > 100000)
if (dept == 'R')
bonus = 2000;
else
bonus = 1500;
else if (sales > 75000)
if (dept == 'R')
bonus = 1250;
else
bonus = 1000;
else
bonus = 0;

==1000

What would be the value of discountRate after the following statements are executed?

double discountRate;
char custType = 'B';
switch (custType)
{
case 'A':
discountRate = .08;
break;
case 'B':
discountRate = .06;
case 'C':
discountRate = .04;
default:
discountRate = 0.0;
}

==0.0



Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL the world's alphabets.
==true

In a switch statement, if two different values for theCaseExpression would result in the same code being executed, you must have two copies of the code, one after eachCaseExpression.
==false

What will be the value of ans after the following code has been executed?

int x = 65;
int y = 55;
if (x >= y)
int ans = x + y;
==120

When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
==false


What is the value of ans after the following code has been executed?

int x = 40;
int y = 40;
int ans = 0;
if (x = y)
ans = x + 10;
==No value, this is a syntax error.

The ________ statement is used to make simple decisions in Java.
==if

What will be printed when the following code is executed?

double x = 45678.259;
DecimalFormat formatter =
new DecimalFormat("#,###,##0.00");
System.out.println(formatter.format(x));

====45,678.26

chapter 2

If the following Java statements are executed, what will be displayed?

System.out.println("The top three winners are\n");
System.out.print("Jody, the Giant\n");
System.out.print("Buffy, the Barbarian");
System.out.println("Adelle, the Alligator");

====
The top three winners are
Jody, the Giant
Buffy, the BarbarianAdelle, the Alligator

 
Variables are classified according to their ________.
==data type

 
Which of the following statements correctly creates a Scanner object for keyboard input?
===Scanner keyboard = new Scanner(System.in);


 
Which of the following is a valid Java statement?
Possible Answers
==String str = "John Doe";

 
A variable's scope is the part of the program that has access to the variable.
==true
 


 
Which of the following is not a rule that must be followed when naming identifiers?

===Identifiers can contain spaces.

 
Character literals are enclosed in ________; string literals are enclosed in ________.
==single quotes; double quotes


Every Java application program must have
==a method named main

The boolean data type may contain values in the following range of values
==true or false


What would be printed out as a result of the following code?

System.out.println("The quick brown fox" +
"jumped over the \n"
"slow moving hen.");

===Nothing. This is an error.

What will be the value of z after the following statements have been executed?

int x = 4, y = 33;
double z;
z = (double) (y / x);

===8.0

What is the result of the following statement?
25/4 + 4 * 10 % 3
==7

What will be the value of z as a result of executing the following code?

int x = 5, y = 28;
float z;
z = (float) (y / x);
===5.0

Variables of the boolean data type are useful for
===Evaluating true/false conditions

This is a variable whose content is read only and cannot be changed during the program's execution of the program
===Named constant

This is normally considered the standard output and standard input devices, and usually refer to the monitor and keyboard.
==console

A Java program must have at least one
==Class definition

Given the declaration double r;, which of the following statements is invalid?
==r = 2.9X106;


If the compiler encounters a statement that uses a variable before the variable is declared, an error will result
==true

What is the result of the following expression?

25 - 7 * 3 + 12/3

==8

What is the result of the following statement?
25/4 + 4 * 10 % 3
==7

The primitive data types only allow a(n) ________ to hold a single value.
==variable

chapter 1

Most commercial software applications are large and complex and are usually developed by a single individual.

===false

RAM is usually
== A volatile type of memory, used only for temporary storage

A byte is a collection of
=Eight bits

The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.
== true

An operating system can be categorized according to
==The number of users they can accommodate

Another term for programs is
==Software

In the Programming Process which of the following is not involved in defining what the program is to do
=Compile code

Colons are used to indicate the end of a Java statement.
=false

This is a cross between human language and a programming language.
==Pseudocode

The contents of a variable cannot be changed while the program is running.
=== false

Byte code instructions are
==Read and interpreted by the JVM

Suppose you are at an operating system command line, and you are going to use the following command to compile a program:
==Make sure you are in the same directory or folder where the MyClass.java file is located


Internally, the central processing unit (CPU) consists of two parts
===The control unit and the arithmetic and logic unit ALU

Which of the following will run the compiled program ReadIt?
==java ReadIt

Which of the following commands will compile a program named ReadIt?
=javac ReadIt.java

The major components of a typical computer system consist of
==All of the above

The original name for Java was
==Oak

The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read
==True

A characteristic of ________ is that only an object's methods are able to directly access and make the changes to the object's data.
==Data hiding

Compiled byte code is also called source code.
== false

Software refers to
==Programs

The data contained in an object is known as ________.
==Attributes

Application software refers to
==The programs that make the computer useful to the user

When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption.
==true