Assume that partNumber references a String object. The following if statement should perform a case-insensitive comparison. What is wrong with it? if (partNumber.equals("BQ789W4")) available = true;
> 21. True or False: The for loop is a posttest loop. 22. True or False: It is not necessary to initialize accumulator variables. 23. True or False: One limitation of the for loop is that only one variable may be initialized in the initialization express
> 11. This expression is executed by the for loop only once, regardless of the number of iterations. 1. initialization expression 2. test expression 3. update expression 4. pre-increment expression 12. This is a variable that keeps a running total. 1. sen
> 1. What will the println statement in the following program segment display? int x = 5; System.out.println(x++); 1. 5 2. 6 3. 0 4. None of these 2. What will the println statement in the following program segment display? int x = 5; System.out.println(+
> Write the code to add the following RadioButton controls to the ToggleGroup. RadioButton radio1 = new RadioButton("Option 1"); RadioButton radio2 = new RadioButton("Option 2"); RadioButton radio3 = new RadioButton("Option 3"); ToggleGroup radioGroup = ne
> 11. When determining whether a number is inside a range, it’s best to use this operator. 1. && 2. ! 3. | | 4. ? : 12. This determines whether two different String objects contain the same string. 1. the == operator 2. the = operator 3. the equals meth
> Find the errors in the following code: The following statement should determine whether x is not greater than 20. What is wrong with it? if (!x > 20)
> Find the errors in the following code: // Warning! This code contains ERRORS! if (x == 1) ; y = 2 ; else if (x == 2) ; y = 3 ; else if (x == 3) ; y = 4 ;
> Find the errors in the following code: // Warning! This code contains ERRORS! if (num2 == 0) System.out.println("Division by zero is not possible."); System.out.println("Please run the program again ") ; System.out.println("and enter a number besides ze
> There are a number of syntax errors in the following program. Locate as many as you can. */ What's wrong with this program /* public MyProgram { public static void main(String[ ] args) ; } int a, b, c \\ Three integers a = 3 b = 4 c = a + b System.out.p
> The following pseudocode algorithm has an error. The program is supposed to ask the user for the length and width of a rectangular room, and then display the room’s area. The program must multiply the width by the length to determine the area. Find the
> The following import statements are in a controller class that uses a Button component and a Label component. import java.fxml.FXML; import java.scene.control.Button; import java.scene.control.Label;
> Find the error: private class MyMouseListener implements MouseListener { public void mouseClicked(MouseEvent e) { mouseClicks += 1; } }
> Find the error: // Force a call to the paint method paint();
> Find the error:
> An application has a Button control named calcButton. Write the statement that assigns the ID "calc-button" to the calcButton control.
> Find the error: // Create a text area with 20 columns and 5 rows. JTextArea textArea = new JTextArea (20, 5);
> Find the error: JLabel label = new JLabel("Have a nice day!"); label.setImage(image) ;
> Find the error: // Create a JList and add it to a scroll pane. // Assume that array already exists. JList list = new JList(array) ; JScrollPane scrollPane = new JScrollPane(); scrollPane.add(list) ;
> Find the error: // Create a read-only text field. JTextField textField = new JTextField(10); textField.setEditable(true);
> Find the error in the following Java code. Assume that conn references a valid Connection object. // This code has an error!!! String sql = "SELECT * FROM Coffee"; Statement stmt = conn.createStatement(); ResultSet result = stmt.execute(sql);
> Find the error in the following SQL statement. SELECT * FROM Coffee WHERE Description = "French Roast Dark”
> The panel variable references a JPanel object. The intention of the following statement is to create a titled border around panel: panel.setBorder(new BorderFactory("Choices"));
> The intention of the following statement is to give the panel object a GridLayout manager with 10 columns and 5 rows: panel.setLayout(new GridLayout(10, 5));
> The following statement is in a class that uses Swing components: import java.swing.*;
> Find the error in the following program: public class FindTheError { public static void main(String[] args) { myMethod(0); } public static void myMethod(int num) { System.out.print(num + " "); myMethod(num + 1); } }
> Write functional RGB notation for a color where red=100, green=20, and blue= 255.
> What will the following code output? int apples = 0, bananas = 2, pears = 10; apples += 10; bananas *= 10; pears /= 10; System.out.println(apples + " " + bananas + " " + pears);
> Find the error: // This code has an error! RadioButton radio1 = new RadioButton("Option 1"); RadioButton radio2 = new RadioButton("Option 2"); ToggleGroup radioGroup = new ToggleGroup(); radioGroup.setToggleGroup(radio1); radioGroup.setToggleGroup(radio2
> Find the error: .button { -fx-background-color = #0000FF; }
> Find the error: // This code has an error! myImageView.setWidth(100); myImageView.setHeight(100);
> Assume hbox is an HBox container: // This code has an error! hbox.setAlignment(CENTER);
> Find the error: // This code has an error! @Override public void start(Scene primaryScene) { primaryScene.show(); }
> Find the error: try { number = Integer.parseInt(str); } catch (Exception e) { System.out.println(e.getMessage()); } catch (IllegalArgumentException e) { System.out.println("Bad number format."); } catch (NumberFormatException e) { System.out.println(str
> Find the error: catch (FileNotFoundException e) { System.out.println("File not found."); } try { File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); }
> Find the error: // Superclass public class Vehicle { private double cost; public Vehicle(double c) { cost = c; } } // Subclass public class Car extends Vehicle { private int passengers; public Car(int p) { passengers = c; } }
> Find the error: // Superclass public class Vehicle { (Member declarations . . .) } // Subclass public class Car expands Vehicle { (Member declarations . . .) }
> Find the error: // Change the very first character of a // StringBuilder object to 'Z'. str.setCharAt(1, 'Z');
> Write a JavaFX CSS style definition that will be applied to all Label, Button, and TextField controls. The style definition should specify the following: font size: 24, font style: italic, font weight: bold.
> Find the error: int number = 99; String str; // Convert number to a string. str.valueOf(number);
> The following class definition has an error. What is it? public class MyClass { private int x; private double y; public static void setValues(int a, double b) { x = a; y = b; } }
> String[] words = { "Hello", "Goodbye" }; System.out.println(words.toUpperCase());
> int[] table = new int[10]; for (int x = 1; x
> Find the error: int[] collection = new int[−20];
> Find the error in the following class: public class FindTheError { public int square(int number) { return number * number; } public double square(int number) { return number * number; } }
> The following statement attempts to create a Rectangle object. Find the error. Rectangle box = new Rectangle;
> Find the error in the following class: public class MyClass { private int x; private double y; public void MyClass(int a, double b) { x = a; y = b; } }
> Find the error in the following method definition: // This method has an error! public static double timesTwo(double num) { double result = num * 2; }
> Find the error in the following method definition: // This method has an error! public static void sayHello(); { System.out.println("Hello"); }
> Write code that creates a Slider control. The control should be horizontally oriented and its range should be 0 through 1000. Labels and tick marks should be displayed. Major tick marks should appear at every 100th number, and minor tick marks should app
> Find the errors in the following code: // This code contains ERRORS! int choice, num1, num2; Scanner keyboard = new Scanner(System.in); do { System.out.print("Enter a number: ") ; num1 = keyboard.nextInt() ; System.out.print("Enter another number: ") ; n
> The following statement should determine whether count is outside the range of 0 through 100. What is wrong with it? if (count < 0 && count > 100)
> Find the errors in the following code: // This code contains ERRORS! // It adds two numbers entered by the user. int num1, num2; String input; char again; Scanner keyboard = new Scanner(System.in); while (again == 'y' || again == 'Y') System.out.print("E
> What does the term multitasking mean?
> Explain why computers have both main memory and secondary storage.
> What is a memory address? What is its purpose?
> Describe the steps in the fetch/decode/execute cycle.
> Internally, the CPU consists of what two units?
> List the five major hardware components of a computer system.
> Write code that creates a ListView control named snackListView. Add the following strings to the ListView: “cheeseâ€, “olivesâ€, “crackersâ€.
> Why is the computer used by so many different people, in so many different professions?
> Why should you be careful when choosing a sentinel value?
> In the following program segment, which variable is the loop control variable (also known as the counter variable) and which is the accumulator? int a, x = 0, y = 0; while (x < 10) { a = x * 2; y += a; x++; } System.out.println("The sum is " + y);
> Write a for loop that repeats seven times, asking the user to enter a number. The loop should also calculate the sum of the numbers entered.
> Write a for loop that displays every fifth number, zero through 100.
> Write a for loop that displays all of the odd numbers, 1 through 49.
> Write a for loop that displays your name 10 times.
> What will the following program segments display? 1. x = 2; y = x++; System.out.println(y); 2. x = 2; System.out.println(x++); 3. x = 2; System.out.println(−−x); 4. x = 8; y = x−−; System.out.println(y);
> Write an if-else statement that assigns 1 to x when y is equal to 100. Otherwise, it should assign 0 to x.
> Write an if-else statement that assigns 20 to the variable y if the variable x is greater than 100. Otherwise, it should assign 0 to the variable y.
> Write a JavaFX CSS style definition that will be applied to all Label controls. The style definition should specify the following: font size: 24, font style: italic, font weight: bold.
> Write an if statement that displays “Goodbye†if the variable myCharacter Âcontains the character 'D'.
> Write an if statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.
> Write an if statement that assigns 20 to the variable y and assigns 40 to the Âvariable z if the variable x is greater than 100.
> Write an if statement that sets the variable fees to 50 if the boolean variable max is true.
> Assume the following declaration exists in a program: String name = "James"; Write a statement that uses System.out.printf to display the value of name in a field that is 20 spaces wide.
> Assume the following variable declaration exists in a program: double number = 123456.789; Write a statement that uses System.out.printf to display the value of the number variable left-justified, with comma separators, in a field that is 20 spaces wide,
> Assume the following variable declaration exists in a program: int number = 123456; Write a statement that uses System.out.printf to display the value of the number variable in a field that is 10 spaces wide, with comma separators.
> Assume the following variable declaration exists in a program: double number = 123.456; Write a statement that uses System.out.printf to display the value of the number variable padded with leading zeros, in a field that is eight spaces wide, rounded to
> Assume the following variable declaration exists in a program: double number = 123.456; Write a statement that uses System.out.printf to display the value of the number variable rounded to one decimal place, in a field that is 10 spaces wide.
> Write an if statement that assigns 0.2 to commission if sales is greater than or equal to 10000.
> Assume gridPane is the name of a GridPane container, and button is the name of a Button control. Write a statement that adds button to gridPane at column 2, row 5.
> Assume the following variable declaration exists in a program: double number = 1234567.456; Write a statement that uses System.out.printf to display the value of the number variable formatted as: 1,234,567.46
> What will the following code display? int funny = 7, serious = 15; funny = serious * 2; switch (funny) { case 0 : System.out.println("That is funny."); break; case 30: System.out.println("That is serious."); break; case 32: System.out.println("That is se
> What is wrong with the following switch statement? // This code has errors!!! switch (temp) { case temp < 0 : System.out.println("Temp is negative."); break; case temp = 0: System.out.println("Temp is zero."); break; case temp > 0 : System.out.println("T
> Explain why you cannot convert the following if-else-if statement into a switch statement. if (temp == 100)  x = 0; else if (population > 1000)  x = 1; else if (rate < .1)  x = −1;
> Rewrite the following if-else-if statement as a switch statement. if (selection == 'A') System.out.println("You selected A."); else if (selection == 'B') System.out.println("You selected B."); else if (selection == 'C') System.out.println("You selected C
> Complete the following program skeleton by writing a switch statement that displays “one†if the user has entered 1, “two†if the user has entered 2, and “three†if the user has entered 3. If a number other than 1, 2, or 3 is entered, the progra
> Rewrite the following if-else statements as statements that use the conditional operator. 1. if (x > y)  z = 1; else  z = 20; 2. if (temp > 45)  population = base * 10; else  population = base * 2; 3. if (hours > 40)  wages *= 1.5; else  wage
> Modify the statement you wrote in response to Checkpoint3.20 so it performs a case-insensitive comparison. Data from Checkpoint 3.20: Assume the variable name references a String object. Write an if statement that displays “Do I know you?†if the Str
> Assume the variables name1 and name2 reference two different String objects, containing different strings. Write code that displays the strings referenced by these variables in alphabetical order.
> Assume the variable name references a String object. Write an if statement that displays “Do I know you?†if the String object contains “Timothyâ€.
> Write a statement, after the following code, that creates an HBox container, adds the label1, label2, and label3 controls to it, and has 10 pixels of spacing between the controls. Label label1 = new Label("One"); Label label2 = new Label("Two"); Label la
> Write an if statement that multiplies payRate by 1.5 if hours is greater than 40.
> Write an if statement that displays the message "The number is not valid" if the variable speed is outside the range 0 through 200.
> Write an if statement that displays the message "The number is valid" if the variable speed is within the range 0 through 200.
> Assume the variables a = 2, b = 4, and c = 6. Circle the T or F for each of the ­following conditions to indicate whether it is true or false.
> The following truth table shows various combinations of the values true and false connected by a logical operator. Complete the table by circling T or F to indicate whether the result of such a combination is true or false.
> The following program is used in a bookstore to determine how many discount Âcoupons a customer gets. Complete the table that appears after the program. import javax.swing.JOptionPane; public class CheckPoint { public static void main(String[] args) { i
> What will the following program display? public class CheckPoint { public static void main(String[] args) { int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } E
> Write code that tests the variable x to determine whether it is greater than 0. If x is greater than 0, the code should test the variable y to determine whether it is less than 20. If y is less than 20, the code should assign 1 to the variable z. If y is