Find the error: // Change the very first character of a // StringBuilder object to 'Z'. str.setCharAt(1, 'Z');
> 21. True or False: The String class’s replace method can replace individual characters, but cannot replace substrings. 22. True or False: The StringBuilder class’s replace method can replace individual characters, but cannot replace substrings. 23.
> 11. To delete a specific character in a StringBuilder object, use this method. 1. deleteCharAt 2. removeCharAt 3. removeChar 4. expunge 12. The character that separates tokens in a string is known as a ___. 1. separator 2. tokenizer 3. delimiter 4. term
> 1. The isDigit, isLetter, and isLetterOrDigit methods are members of this class. 1. String 2. Char 3. Character 4. StringBuilder 2. This method converts a character to uppercase. 1. makeUpperCase 2. toUpperCase 3. isUpperCase 4. uppercase 3. The starts
> 11. CRC stands for 1. Class, Return value, Composition 2. Class, Responsibilities, Collaborations 3. Class, Responsibilities, Composition 4. Compare, Return, Continue 12. True or False: A static member method may refer to non-static member variables of
> 1. This type of method cannot access any non-static member variables in its own class. 1. instance 2. void 3. static 4. non-static 2. When an object is passed as an argument to a method, this is actually passed. 1. a copy of the object 2. the name of th
> Write a statement that instantiates the Line class, and uses the constructor to draw a line from (50, 25) to (150, 125).
> 21. True or False: The first size declarator in the declaration of a two-dimensional array represents the number of columns. The second size declarator represents the number of rows. 22. True or False: A two-dimensional array has multiple length fields.
> 11. To insert an item at a specific location in an ArrayList object, you use this method. 1. store 2. insert 3. add 4. get 12. To delete an item from an ArrayList object, you use this method. 1. remove 2. delete 3. erase 4. get 13. To determine the num
> 1. In an array declaration, this indicates the number of elements that the array will have. 1. subscript 2. size declarator 3. element sum 4. reference variable 2. Each element of an array is accessed by a number known as a(n) ___. 1. subscript 2. size
> 11. This is automatically provided for a class if you do not write one yourself. 1. accessor method 2. default instance 3. default constructor 4. variable declaration 12. Two or more methods in a class may have the same name, as long as this is differen
> 1. This is a collection of programming statements that specify the fields and methods that a particular type of object may have. 1. class 2. method 3. parameter 4. instance 2. A class is analogous to a(n) ___. 1. house 2. blueprint 3. drafting table 4.
> 11. True or False: When passing an argument to a method, Java will automatically perform a widening conversion (convert the argument to a higher-ranking data type), if necessary. 12. True or False: When passing an argument to a method, Java will automat
> 1. This type of method does not return a value. 1. null 2. void 3. empty 4. anonymous 2. This appears at the beginning of a method definition. 1. semicolon 2. parentheses 3. body 4. header 3. The body of a method is enclosed in ___. 1. curly braces { }
> 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 . . .) }
> 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
> 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;
> 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