Ch 1
Ch 2
Ch 3
Ch 4 Part I
Ch 4 Part II
100
____________________ is a tool that helps programmers plan a program’s logic by writing plain English statements.
What is Pseudocode
100
import javax.swing.JOptionPane;
public class salesJune
{
public static void main(String[] args)
{
int storeSales = 250;
}
}

In the above code, complete the statement that will display a message dialog box that will appear centered on the screen and will display the following text: Congratulations! June sales were $250!
. JOptionPane.showMessageDialog(null, "Congratulations! June sales were $" + storeSales + "!";
100
What is wrong with the following statement? How could you correct it?
if(payRate < 5.85 && payRate > 60)
System.out.println("Error in pay rate");
As a single variable, no payRate value can ever be both below 5.85 and over 60 at the same time. Therefore, the output statement can never execute, no matter what value the payRate has. In this case, you must write the following code to print the error message under the correct circumstances:
if(payRate < 5.85 || payRate > 60)
System.out.println("Error in pay rate");
100
How could you rewrite the following code to have the arithmetic performed only once, even if the loop executes 1,000 times?
while (x < a + b)
// loop body
int sum = a + b;
while(x < sum)
// loop body
100
Explain the difference between an absolute path and a relative path. Provide an example of an absolute path to a file on a system, and then provide an example of a relative path.
Every Path is either absolute or relative. An absolute path is a complete path that does not need any other information to locate a file on a system. A relative path depends on other path information.
C:\Java\Chapter.13\SampleFile.txt is an example of an absolute path.
A relative path depends on other path information. A simple path such as SampleFile.txt is relative. When you work with a path that contains only a filename, the file is assumed to be in the same folder as the program using it. Similarly, when you refer to a relative path such as Chapter.13\SampleFile.txt (without the drive letter or the top-level Java folder), the Chapter.13 folder is assumed to be a subfolder of the current directory, and SampleFile.txt is assumed to be within the folder.
200
What is the difference between volatile and nonvolatile storage in Java programming? Give examples of different storage situations.
Volatile storage is temporary; values that are volatile, such as those stored in variables, are lost when a computer loses power. Random access memory (RAM) is the temporary storage within a computer. When you write a Java program that stores a value in a variable, you are using RAM. Most computer professionals simply call volatile storage memory. Nonvolatile storage is permanent storage; it is not lost when a computer loses power. When you write a Java program and save it to a disk, you are using permanent storage.
200
final int COST_PER_ITEM= 10;
double sales2012 = amtSold * COST_PER_ITEM;
In the above statements, identify the named constant and describe how a programmer can recognize named constants.
The named constant identifier is COST_PER_ITEM. Constant declaration statements use the final keyword. Constants are conventionally given identifiers in all uppercase letters.
200
if (maxValue = 100)
System.out.println ("Your limit has been reached");
Why is the above if statement illegal? How would you fix it?
A common programming error occurs when a programmer uses a single equal sign rather than a double equal sign when attempting to determine equivalency. The expression maxValue = 100 does not compare maxValue to 100. Instead, it attempts to assign the value 100 to maxValue. When the expression maxValue = 100 is used in the if statement, the assignment is illegal because only Boolean expressions are allowed. Then, if statement should be written as: if(maxValue == 100)
System.out.println("Your limit has been reached");
200
counterLoop = 1;
while(counterLoop < 10);
{
System.out.println("Hello");
counterLoop = counterLoop + 1;
}
What is the problem in the above while loop? How would you correct the problem?
The placement of the statement-ending semicolon is important when you work with the while statement. In the code, a semicolon is mistakenly placed at the end of the partial statement while(counterLoop < 10). This makes the loop infinite. This loop has an empty body, or a body with no statements in it. The Boolean expression is evaluated; and because it is true, the loop body is entered. Because the loop body is empty, no action is taken, and the Boolean expression is evaluated again. Nothing has changed, so it is still true, the empty body is entered, and the infinite loop continues.
200
The ____________________ loop is the posttest loop used in Java.
do-while
300

public class FindMyErrors
{
public static void main(String[] args)
{
System.out.println(“My application with errors)
}

Given the above code, identify three separate syntax errors.
There is a semicolon missing at the end of the println statement that will produce the output. There is a missing curly brace. Curly braces must be open and closing pairs. There are missing quotation marks in the println statement that will produce the output.
300
System.out.println(“First Java application”);
Given the above code, identify and describe the use of a literal string and the use of parentheses.
A literal string is a series of characters that will appear exactly as entered. Any literal string in Java is written between double quotation marks. The string “First Java application” appears within parentheses because the string is an argument to a method, and arguments to methods always appear within parentheses.
300
You are never required to use a ____________________ structure; you can always achieve the same results with nested if statements.
What is switch
300

public class IncrDemo
{
public static void main(String[] args)
{
int myVal, yourVal;
myVal = 10;
System.out.println("My initial value is " + myVal);
yourVal = ++myVal;
System.out.println("My new value is " + myVal);
System.out.println("Your value is " + yourVal):
}
}

Using the above code, describe how the three println output commands will appear. Explain the values stored in the variables during code execution.
The myVal variable is initialized to 10. The first println statement will display: “My initial value is 10”. myVal is then incremented by 1 and the value is stored in yourVal. At this point, both myVal and yourVal have a value of 11. The second println statement will display: “My new value is 11.” And the third println statement will display: “Your value is 11.”
300
How can you assign program output to a file, rather than to the standard output device? Explain how this works. Give an example.
Instead of using the standard output device, you can create a new PrintWriter object specifying the desired the name of the file you want to write to as the argument. You can then call the print, println, and printf methods on the PrintWriter object just like you would with System.out.
400
The brains of the computer
The CPU
400
____________________ comments are a special case of block comments that are used to generate documentation.
What is Javadoc
400
What is wrong with the following statement? How could you correct it?
if(payRate < 5.85 && payRate > 60)
System.out.println("Error in pay rate");
As a single variable, no payRate value can ever be both below 5.85 and over 60 at the same time. Therefore, the output statement can never execute, no matter what value the payRate has. In this case, you must write the following code to print the error message under the correct circumstances:
if(payRate < 5.85 || payRate > 60)
System.out.println("Error in pay rate");
400
while(10 > 1)
{
System.out.println("Hello!");
}
Identify the problem that exists in the above while loop.
The above code is an infinite loop. The expression 10 > 1 will always evaluate to true. Since this expression is part of a while loop, the body of the loop is entered and “Enter a new value” is displayed. Next, the expression is evaluated again. The expression 10 > 1 is still true, so the body is entered again. “Enter a new value” is displayed repeatedly. The loop never finishes because 10 > 1 is never false.
400
What tasks are typically performed when working with stored files in an application?
When you work with stored files in an application, you typically perform the following tasks: * Specifying the file using its path * Writing to the file OR * Reading from the file * Closing the file
500
The CPU consists of two parts: the Control Unit and the _________________.
What is the Arithmetic Logic Unit
500
. public class YourGrade { public static void main(String[] args) { int projectPoints = 89; System.out.print("Your grade for this class is "); System.out.print(projectPoints); System.out.println("%"); } } Given the above code, what will be the output at the command prompt?
Output will be as follows: Your grade for this class is 89%

(A blank line will follow the output.)
500
if(firstValue == secondValue)
{
int total = firstValue + secondVaue;
System.out.println("The values are equal");
}
System.out.println("The total is " + total);
Why will the above println() statement cause an error?
When blocking statements, it is crucial to remember that any variable declared within the block is only in scope in that block. In the above code, a variable named total is in scope in the if-block, but not after. The ending println statement causes an error because the total variable is not recognized.
500
What are the three sections inside the parentheses of a for loop typically used for?
. You begin a for loop with the keyword for followed by a set of parentheses. Within the parentheses are three sections separated by exactly two semicolons. The three sections are usually used for the following: Initializing the loop control variable Testing the loop control variable Updating the loop control variable
500
Fill in the line of code to generate a random number between 1 and 40 and assign it to the variable num :
import java.util.Random;
public class Lotto{
public static void main(String[] args){
Random myRandom = new Random();
int num;
______________________
System.out.println("And the winner is: " + num);
}
}
num = myRandom.nextInt(40) + 1;
M
e
n
u