When using an array, what can be used to determine the number of elements in the
ID: 3770499 • Letter: W
Question
When using an array, what can be used to determine the number of elements in the array? use the array’s length() method use the array’s length property use the array’s size() method use the array’s size property Flag this Question
Question 2 1 pts Overriding is when you: define a class using the same class name but a different number of parameters define two classes using the same name but different constructors define a method in a subclass and superclass with the same name. define two methods with the same name but different number of parameters Flag this Question
Question 3 1 pts To access an element in an Array object, use the array’s index value. use the element() method. use the get() method. use the position property. Flag this Question
Question 4 1 pts To access an element in an ArrayList object, use the array’s index value. use the element() method. use the get() method. use the position property. Flag this Question
Question 5 1 pts Which GUI component would be used to allow text to be entered? a JTextField a JTextBox a JTextFrame a JTextLabel Flag this Question
Question 6 1 pts Which method call would change the window title to “Hello”? setTitle(“Hello”) setWindowTitle(“Hello”) setFrame(“Hello”) setFrameTitle(“Hello” Flag this Question
Question 7 1 pts When a button-click event occurs, which item below must be implemented? ActionEvent interface ActionPerformed interface AactionListener interface WindowListener interface Flag this Question
Question 8 1 pts Which method should be used to determine which component caused the fired event? getInstance() getSource() getEvent() getActionCommand() Flag this Question
Question 9 1 pts Which layout manager causes components to be positioned in the top-center position? BorderLayout FlowLayout GridBagLayout GridLayout GridlessLayout Flag this Question Question
10 1 pts Which two methods come from the Component class which is an ancestor of the JFrame class? setTitle() setDefaultCloseOperation() setLayout() setVisible() Flag this Question
Question 11 1 pts Which is the proper way to enable Line Wrap on a JTextArea? setLineWrap(1); setLineWrap(word); setLineWrap(true); setLineWrap(on); True/False questions: circle the best answer. Flag this Question
Question 12 1 pts When using Short-circuit evaluation, if the left side of an “and” operation is false, the right side is not evaluated. True False Flag this Question
Question 13 1 pts The following is an example of a “Ternary” operator. (a > b) ? x : y True False Flag this Question
Question 14 1 pts A “catch” block can only check one exception at a time. Subsequent catch blocks are needed for each additional exception. True False Flag this Question
Question 15 1 pts Use of the access modifier public provides for better encapsulation and ensures access is possible for any class needed direct access to the variable in question. True False Flag this Question
Question 16 1 pts When using parseInt() to convert a String to a number, a non-integer value causes a runtime error. True False Flag this Question
Question 17 1 pts The getSource method is used to determine the component causing the event that was fired from inside an actionPerformed method. True False Flag this Question
Question 18 1 pts Write the statement to access the 8th element of the array defined below? Integer [] priceList = new Integer [10]; Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 19 1 pts Skip to question text. Add the variable called input to the ArrayList declared below. private static ArrayList floors = new ArrayList<>(); Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 20 2 pts Write the code on a single line to display the dialog box below. Keyboard Shortcuts Font Sizes Paragraph p Flag this Question Question 21 1 pts What type of variable would the input from the following Input Dialog be stored in? Integer String Line Double Flag this Question
Question 22 2 pts Skip to question text. Given the following array declaration, what statement would print out Blueberry – 3.14 to the screen? double [] myNumbers = new double[]{1.23, 3.14, 5.18, 82, 2.56}; String [] myPi = new String[]{"Strawberry", "Lemon", "Blueberry", "Apple", "Pumpkin"}; System.out.println(System.out.println(myPi[3] + " - " + myNumbers[2]);); System.out.println(System.out.println(myPi[3] & " - " & myNumbers[2]);); System.out.println(System.out.println(myPi[2] & " - " & myNumbers[1]);); System.out.println(System.out.println(myPi[2] + " - " + myNumbers[1]);); Flag this Question
Question 23 2 pts Skip to question text. Assume that this code fragment compiles and runs. What is its output? As always, be precise when showing your output. public static void main(String [] args) { int x = 3; int xf = 0; if (x == 0 || x == 1) { xf = 1; } else { xf = 1; for (int i=2; i<=x; i++) { xf *= i; } } System.out.println("Results are: " + xf); } Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 24 2 pts Skip to question text. Assume that this program compiles and runs. Assume that the user enters 5 6 (separated by a space) for input. What is the output? As always, be precise when showing your output. import java.util.Scanner; public class TryCatchQuestion { public static void main(String [] args) { Scanner stdIn = new Scanner(System.in); System.out.println("Please enter 2 numbers seperated by a space"); try { System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt()); } catch (NumberFormatException e) { System.out.println("Number Format Exception"); } catch (ArithmeticException e) { System.out.println("Division by zero"); } catch (Exception e) { System.out.println("Other Exception"); } }//end main }//end TryCatchQuestion Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 25 2 pts Skip to question text. Assume that this program compiles and runs. Assume that the user enters 5 0 (separated by a space) for input. What is the output? As always, be precise when showing your output. import java.util.Scanner; public class TryCatchQuestion { public static void main(String [] args) { Scanner stdIn = new Scanner(System.in); System.out.println("Please enter 2 numbers seperated by a space"); try { System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt()); } catch (NumberFormatException e) { System.out.println("Number Format Exception"); } catch (ArithmeticException e) { System.out.println("Division by zero"); } catch (Exception e) { System.out.println("Other Exception"); } }//end main }//end TryCatchQuestion Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 26 2 pts Skip to question text. Assume that this program compiles and runs. Assume that the user enters 5 six (separated by a space) for input. What is the output? As always, be precise when showing your output. import java.util.Scanner; public class TryCatchQuestion { public static void main(String [] args) { Scanner stdIn = new Scanner(System.in); System.out.println("Please enter 2 numbers seperated by a space"); try { System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt()); } catch (NumberFormatException e) { System.out.println("Number Format Exception"); } catch (ArithmeticException e) { System.out.println("Division by zero"); } catch (Exception e) { System.out.println("Other Exception"); } }//end main }//end TryCatchQuestion Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 27 4 pts Skip to question text. Provide code that adds the three buttons to the window shown below. Only provide the code for the layout manager and the buttons. No additional code is required. (4 points: 1 Layout; 1 each button) Keyboard Shortcuts Font Sizes Paragraph p Flag this Question
Question 28 14 pts Skip to question text. Provide the code for a class called Grades.java that would work with the driver class provided below. import java.util.Random; public class Driver { public static void main(String [] args) { Grades [] studentGrades = new Grades[25]; for (int x=0; x< studentGrades.length; x++) studentGrades[x] = new Grades(); Random rand = new Random(); for (int x=0; x< studentGrades.length; x++) { int grade = rand.nextInt(51)+50; studentGrades[x].addEntry(grade); } Grades.showResults(studentGrades) ; } } When the program runs, the following random output should be produced: (numbers will vary due to random) Lowest Grade: 60 Highest Grade: 99 Average: 78 Program specific requirements for Grades class: •Declare 3 static variables for lowest, highest, and average grades. 3 pt •Declare 1 instance variable to hold the grade. 1 pt •addEntry Method provide a proper header which receives grade as input 1 pt store received grade in instance variable 1 pts •showResults Method provide a proper class method header which receives array 1 pt utilize a for loop to iterate through array 1 pt add up grades into total static variable 1 pt set low to lowest grade received 1 pt set high to highest grade received 1 pt output lowest grade 1 pt output highest grade 1 pt output average grade 1 pt
Explanation / Answer
Hi,
Below are the solutions to your questions,The way you have posted the questions is a little clumsy i will try to answer all of them by understanding your questions:
Question 1:
Solution:In order to find the number of elements in an array we use array length() method.
Question 2:
Solution:Overriding is to define a method in a subclass and superclass with the same name.
Question 3:
Solution: In order to access an element in an Array object, use the array’s index value.
Question 4:
Solution:In order to access an element in an ArrayList object,you need to use get which,Returns the element at the specified position in this list
Question 5:
Solution:For a text to be entered in the GUI we need to use JTextField.
Question 6:
Solution:setTitle(“Hello”) method can be used to set the title name as "Hello" for the window.
Question 7:
Solution:Whenever a button is clicked a ActionListener interface must be implemented.
Question 8:
Solution:getSource() method returns the object that generates the event.
Question 9:
Solution:When adding a component to a container, specify the component's location (for example, BorderLayout.CENTER) will cause layout manager components to be positioned in the top-center position
Question 10:
Solution: setLayout() and setVisible() are the two methods that come from the Component class which is an ancestor of the JFrame class.
Quesion 11:
Solution: setLineWrap(true); is the proper way to enable Line Wrap on a JTextArea.
Question 12:
Solution:The answer is "True".
Question 13:
Solution:(a > b) ? x : y is a ternary operator so teh answer is "True".
Question 14:
Solution:A “catch” block can only check one exception at a time. Subsequent catch blocks are needed for each additional exception.So the answer is "True"
Question 15:
Solution:False,Actually private access modifier provides encapsulation and not public.
Question 16:
Solution:When using parseInt() to convert a String to a number, a non-integer value causes a runtime error--TRUE.
Question 17:
Solution:An event object contains a reference to the component that generated the event. To extract that reference from the event object use getSource() method.-->True
Question 18:
Solution:priceList[7] will give the 8th element from this array priceList.
Question 19:
Solution:I really cannot understand the rest of your questions as they are cluttered and clumsy please add the questions again clealy will be able to answer then.
Hope that helps...HAPPY ANSWERING!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.