Quiz 2 Flashcards
What does testing an application entail?
Running it to see if it works correctly.
What happens when you use both integer and double values in an arithmetic expression?
the integer values are cast to double values
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;
}
4
A runtime error occurs when
bytecodes can’t be interpreted properly
The double data type can be used to store
floating-point numbers
According to standard naming conventions, which of the following is a typical class name?
Product
What happens when a logical error occurs?
The results of the application will be inaccurate.
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?
employeePhoneNumber
Unlike other methods, a static method
is called directly from a class
If a class contains a main method, that method is executed
when the class is run
To refer to a Java class from an application without qualification, you need to import the class unless that class
is stored in a package that has already been imported
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
end
Block scope means that a variable
can’t be used outside of the set of braces that it’s declared in
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
InvoiceApp.java
The int data type can be used to store
whole numbers only
What does the following statement do in a Java application?
import java.util.Scanner;
It makes the Scanner class available to the application without qualification.
A compile-time error occurs when
there’s a syntax error in a Java statement
What happens when a runtime error occurs?
The application will end abnormally.
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(); } } }
Subtotal = 100.0
Sales tax = 8.75
Invoice total = 108.75
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;
. 40.0
What does debugging an application entail?
Identifying and fixing any bugs.
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.”);
22
is Tom’s age.
Which of the following can you not use the Java API documentation to research?
debuggers
Which of the following can you assign to a String variable?
all of the above