Quiz 2 Flashcards

1
Q

What does testing an application entail?

A

Running it to see if it works correctly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens when you use both integer and double values in an arithmetic expression?

A

the integer values are cast to double values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How many times will the while loop that follows be executed if months has a value of 5?
int i = 1;
while (i < months)
{
futureValue = futureValue * (1 + monthlyInterestRate);
i = i+1;
}

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A runtime error occurs when

A

bytecodes can’t be interpreted properly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The double data type can be used to store

A

floating-point numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

According to standard naming conventions, which of the following is a typical class name?

A

Product

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when a logical error occurs?

A

The results of the application will be inaccurate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Based on the naming recommendations in the book, which of the following is a good identifier for a variable that will be used to hold an employee’s phone number?

A

employeePhoneNumber

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Unlike other methods, a static method

A

is called directly from a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If a class contains a main method, that method is executed

A

when the class is run

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

To refer to a Java class from an application without qualification, you need to import the class unless that class

A

is stored in a package that has already been imported

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

import java.util.Scanner;

public class InvoiceApp
{
 public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
 String choice = "y";
 while (choice.equals("y"))
 {
 System.out.print("Enter subtotal: ");
 double subtotal = sc.nextDouble();
 double salesTax = subtotal * .0875;
 double invoiceTotal = subtotal + salesTax;
 String message = "Subtotal = " + subtotal + "\n"
 \+ " Sales tax = " + salesTax + "\n"
 \+ "Invoice total = " + invoiceTotal + "\n\n"
 System.out.println(message);
 System.out.print("Continue? Enter y or n: ");
 choice = sc.next();
 }
 }
}

(Refer to code example 2-1.) If the user enters “Y” when asked if he/she wants to continue, the application will

A

end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Block scope means that a variable

A

can’t be used outside of the set of braces that it’s declared in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

import java.util.Scanner;

public class InvoiceApp
{
 public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
 String choice = "y";
 while (choice.equals("y"))
 {
 System.out.print("Enter subtotal: ");
 double subtotal = sc.nextDouble();
 double salesTax = subtotal * .0875;
 double invoiceTotal = subtotal + salesTax;
 String message = "Subtotal = " + subtotal + "\n"
 \+ " Sales tax = " + salesTax + "\n"
 \+ "Invoice total = " + invoiceTotal + "\n\n"
 System.out.println(message);
 System.out.print("Continue? Enter y or n: ");
 choice = sc.next();
 }
 }
}

(Refer to code example 2-1.) The name of the file that contains this source code must be

A

InvoiceApp.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The int data type can be used to store

A

whole numbers only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the following statement do in a Java application?

import java.util.Scanner;

A

It makes the Scanner class available to the application without qualification.

17
Q

A compile-time error occurs when

A

there’s a syntax error in a Java statement

18
Q

What happens when a runtime error occurs?

A

The application will end abnormally.

19
Q

import java.util.Scanner;

public class InvoiceApp
{
 public static void main(String[] args)
 {
 Scanner sc = new Scanner(System.in);
 String choice = "y";
 while (choice.equals("y"))
 {
 System.out.print("Enter subtotal: ");
 double subtotal = sc.nextDouble();
 double salesTax = subtotal * .0875;
 double invoiceTotal = subtotal + salesTax;
 String message = "Subtotal = " + subtotal + "\n"
 \+ " Sales tax = " + salesTax + "\n"
 \+ "Invoice total = " + invoiceTotal + "\n\n"
 System.out.println(message);
 System.out.print("Continue? Enter y or n: ");
 choice = sc.next();
 }
 }
}
A

Subtotal = 100.0
Sales tax = 8.75
Invoice total = 108.75

20
Q
After the if statement that follows is executed, what will the value of discountAmount be?
double discountAmount = 0.0;
double orderTotal = 200.0;
if (orderTotal > 200)
 discountAmount = orderTotal * .3;
else if (orderTotal > 100) 
 discountAmount = orderTotal * .2;
else
 discountAmount = orderTotal * .1;
A

. 40.0

21
Q

What does debugging an application entail?

A

Identifying and fixing any bugs.

22
Q

Assume userName equals “Tom” and userAge equals 22. What is printed on the console when the following statement is executed?
System.out.println(userAge + “ \nis “ + userName + “‘s age.”);

A

22

is Tom’s age.

23
Q

Which of the following can you not use the Java API documentation to research?

A

debuggers

24
Q

Which of the following can you assign to a String variable?

A

all of the above

25
Q

Which of the following can you not assign to a numeric variable?

A

null