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