programming
Question 1 1 pts Skip to question text.
As part of a bank account implementation, there is an account class and a checking account class. These two classes should be related by:
|
|
polymorphism |
|
|
abstract classes |
|
|
both composition and inheritance |
|
|
inheritance |
|
|
composition |
Flag this Question
Question 2 1 pts
When using OOP, which of the following terms refers to a mechanism for a behavior, basically how it’s implemented?
|
|
composition |
|
|
inheritance |
|
|
polymorphism |
|
|
dynamic binding |
Flag this Question
Question 3 1 pts
To access an element in an Array object,
|
|
Use the ArrayList's get() method. |
|
|
Use the ArrayList's element() method. |
|
|
Individual elements in an ArrayList can’t be accessed without doing a sequential query getSequential(), returning every element up to and including the element requested. |
|
|
Use square brackets around an index value. |
Flag this Question
Question 4 1 pts
To access an element in an ArrayList object,
|
|
Use square brackets around an index value. |
|
|
Use the ArrayList element() method. |
|
|
Use the ArrayList get() method. |
|
|
Individual elements in an ArrayList can’t be accessed without doing a sequential query getSequential(), returning every element up to and including the element requested. |
Flag this Question
Question 5 1 pts
What term below is defined as a message that tells the program that something has happened?
|
|
an interaction |
|
|
a listener |
|
|
an action |
|
|
an event |
Flag this Question
Question 6 1 pts
Which item below is defined as an object?
|
|
A String |
|
|
An Array |
|
|
All of the above |
|
|
An ArrayList |
Flag this Question
Question 7 1 pts
When a text-box-enter event occurs, which method and parameter are required to handle this type of action? (1 point)
|
|
actionEvent with an actionperformed parameter |
|
|
actionListener with an interfaceID parameter |
|
|
windowListener with an eventID parameter |
|
|
actionPerformed with an actionEvent parameter |
Flag this Question
Question 8 1 pts
Which class includes the setTitle and setSize methods?
|
|
JFrame |
|
|
JWindow |
|
|
JBox |
|
|
JOptionpane |
Flag this Question
Question 9 1 pts
Before utilizing the binary search method, __________ must be done to the array?
|
|
indexing |
|
|
splitting |
|
|
sorting |
|
|
importing |
Flag this Question
Question 10 1 pts
Which layout manager implements a one-compartment layout scheme?
|
|
GridlessLayout |
|
|
GridBagLayout |
|
|
GridLayout |
|
|
FlowLayout |
|
|
BorderLayout |
Flag this Question
Question 11 1 pts
What is the default layout manager for a JFrame window?
|
|
GridBagLayout |
|
|
GridLayout |
|
|
FlowLayout |
|
|
GridlessLayout |
|
|
BorderLayout |
Flag this Question
Question 12 1 pts
To call the superclass constructor, super() must be the first line in a constructor.
|
|
True |
|
|
False |
Flag this Question
Question 13 1 pts
Method overriding is when a method has the same name, same sequence of parameter types, and the same return type as a method in a superclass.
|
|
True |
|
|
False |
Flag this Question
Question 14 1 pts
Type casting, also known as promotion is considered an implicit conversion.
|
|
True |
|
|
False |
Flag this Question
Question 15 1 pts
An abstract method declaration should always be defined as public as it is meant to be inherited into a subclass to be correctly used.
|
|
True |
|
|
False |
Flag this Question
Question 16 1 pts
When using parseInt() to convert a string to a number, NumberFormatException is thrown if a non-integer argument is found.
|
|
True |
|
|
False |
Flag this Question
Question 17 1 pts
enableEdit() is used to allow a user to edit the contents of a JTextField.
|
|
True |
|
|
False |
Flag this Question
Question 18 1 pts
Write the statement to print to the screen the 6th element of the array defined below?
Integer [ ] priceList = new Integer [10];
p
Flag this Question
Question 19 1 pts
Declare and initialize an ArrayList of type Double and call this ArrayList stocks.
p
Flag this Question
Question 20 1 pts
Write the code on a single line to display the dialog box below. Error! Filename not specified.
p
Flag this Question
Question 21 1 pts Skip to question text.
Write the code on a single line to display the input box below. Save the results into a variable called “input". Error! Filename not specified.
p
Flag this Question
Question 22 4 pts Skip to question text.
Declare (do not initialize) two arrays:
1. One array called “myNumbers” will hold the values: 1.23, 3.14, 5.18, 82, 2.56. The array should not have any additional empty elements.
2. One array called “myNames” will hold the values: Tom, Bob, John, Steve. The array should not have any additional empty elements.
Proper syntax is required
p
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);
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
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
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
p
Flag this Question
Question 27 3 pts Skip to question text.
Provide code that adds "Hello!" and "Goodbye." messages to the JFrame window so that the resulting window looks like this: Error! Filename not specified.
You may assume that the JFrame window has been created using its default layout manager. Provide only two statements – one statement creates "Hello!" and adds it to the window and one statement creates "Goodbye." and adds it to the window. Do not provide extra code. In particular, you should not provide code for window settings (size, title, etc.), and you should not provide code for a listener. (3 points)
p
Flag this Question
Question 28 14 pts Skip to question text.
Provide the code for a class called Coin.java that implements the main method provided below.
public static void main(String [] args)
{
Coin toss = new Coin();
for (int x = 0; x < 1000; x++)
toss.flip();
Coin.results();
}//end main
When the program runs, the following random output should be produced: (numbers will vary as are random)
Heads: 494 Tails: 506
Program specific requirements:
· Style is require but comments are NOT required. 1 pt
· Include appropriate import statements for your file. 1 pt
· Utilize a constant class array to hold “Heads” and “Tails” 1 pt
· Declare a class ArrayList called flips that will hold integer values, 0 for heads and 1 for tails 1 pt
· Create a flips method that performs the following: 4 pts
· Initializes an instance of the Random class and a random variable
· Stores a random variable either 0 or 1
· Store the random number in the flips ArrayList
· Create a results method that performs the following: 6 pts
· Declare variable to hold number of heads flipped
· Utilize a for loop to iterate through the ArrayList (do NOT hard code the size here)
· For each iteration, increment the result from the ArrayList into a variable called heads
· Output the number of Heads using the constant array for the “Heads” heading along with the number of heads flipped
· Output the number of Tails using the constant array for the “Tails” heading along with the number of tails calculated from the size of the array minus the number of heads