Exam 10: Polymorphism
Exam 1: Introduction65 Questions
Exam 2: Data and Expressions77 Questions
Exam 3: Using Classes and Objects58 Questions
Exam 4: Writing Classes56 Questions
Exam 5: Conditionals and Loops37 Questions
Exam 6: More Conditionals and Loops36 Questions
Exam 7: Object-Oriented Design76 Questions
Exam 8: Arrays70 Questions
Exam 9: Inheritance71 Questions
Exam 10: Polymorphism70 Questions
Exam 11: Exceptions68 Questions
Exam 12: Recursion68 Questions
Exam 13: Collections68 Questions
Select questions type
The GUI should react whenever the JButton is clicked, so the JFrame will need an ActionListener. Write the actionPerformed method to implement the ActionListener so that the GUI will compute the cost of the movie when the JButton is clicked. This method will have to obtain the values specified in the JComboBox and the JSlider and output the computed cost in the JLabel. Assume that a Matinee costs $5.00 per ticket, a Rush Hour show $3.50 per ticket and Normal show costs $7.50 per ticket.
Free
(Essay)
4.9/5
(44)
Correct Answer:
public void actionPerformed(ActionEvent ae)
{
String type = (String) jcb.getSelectedItem( );
double rate = 0;
if (type.equals("Matinee"))
rate = 5.00;
else if (type.equals("Rush Hour"))
rate = 3.50;
else
rate = 7.50;
int number = js.getValue( );
double price = rate * number;
NumberFormat nf = NumberFormat.getCurrencyInstance( );
jl.setText(nf.format(price));
}
Which of the following GUI components would you use to display a list of options when the component is first clicked so that the user could select between the entries?
Free
(Multiple Choice)
4.8/5
(40)
Correct Answer:
A
Regarding the Software Failure: There was a segment in the Ariana 5 software to convert a floating-point number to a signed 16-bit integer, but once the number was converted, it was out of range for 16 bits.
Free
(True/False)
4.9/5
(40)
Correct Answer:
True
Comparing the performance of selection sort and insertion sort, what can one say?
(Multiple Choice)
4.8/5
(38)
Which of the following GUI components would you use to allow the user to move the view of the components within the container?
(Multiple Choice)
4.9/5
(45)
What is printed by the following code?
Public class Inherit
{
Abstract class Speaker
{
Abstract public void speak( );
}
Class Cat extends Speaker
{
Public void speak( )
{
System.out.println("Woof!");
}
}
Class Dog extends Speaker
{
Public void speak( )
{
System.out.println("Meow!");
}
}
Inherit( )
{
Speaker d = new Dog( );
Speaker c = new Cat( );
d.speak( );
c.speak( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
(Multiple Choice)
4.9/5
(44)
Choosers-like file choosers and color choosers-provide a mechanism for a user to make a selection among numerous alternatives, and these mechanisms are provided within the Java packages.
(True/False)
4.8/5
(37)
The type of the reference, not the type of the object, is use to determine which version of a method is invoked in a polymorphic reference.
(True/False)
4.8/5
(37)
Write a set of code that will allow a user to select a file through a JFileChooser and store all items in the String array list to the selected file, closing the file when done.
(Essay)
4.8/5
(31)
Explain how to alter the Selection Sort algorithm so that it sorts in descending order instead of ascending order.
(Essay)
4.9/5
(41)
An int array stores the following values. Use the array to answer these next questions.
-Which of the following lists of numbers would accurately show the array after the fourth pass of the Selection Sort algorithm?

(Multiple Choice)
4.8/5
(44)
What is printed?
Public class Inherit
{
Class Figure
{
Void display( )
{
System.out.println("Figure");
}
}
Class Rectangle extends Figure
{
Void display( )
{
System.out.println("Rectangle");
}
}
Class Box extends Rectangle
{
Void display( )
{
System.out.println("Box");
}
}
Inherit( )
{
Figure f = new Figure( );
Rectangle r = new Rectangle( );
Box b = new Box( );
f.display( );
f = r;
((Figure) f.display( );
f = (Figure) b;
f.display( );
}
Public static void main(String[ ] args)
{
New Inherit( );
}
}
(Multiple Choice)
4.9/5
(28)
Comparing the amount of memory required by selection sort and insertion sort, what can one say?
(Multiple Choice)
4.8/5
(42)
A JSlider provides a list of String choices that the user can select between.
(True/False)
4.7/5
(30)
Demonstrate how the following array is sorted using Selection Sort. Show the array after each pass of the outer loop.
[16, 3, 12, 13, 8, 1, 18, 9]
(Essay)
4.8/5
(30)
The fact that the System.out.println( ) method is able to handle such a wide variety of objects, and print them correctly, is an example of the polymorphic nature of the println( ) method.
(True/False)
4.9/5
(40)
An interface name can be used to declare an object reference variable.
(True/False)
4.7/5
(42)
Although insertion sort and selection sort have generally the same O(n²) performance, selection sort has an advantage of insertion sort. What is this advantage?
(Multiple Choice)
4.9/5
(36)
As explained in the Software Failure, the destruction of the Ariane 5 expendable launch system was caused by
(Multiple Choice)
4.9/5
(34)
Showing 1 - 20 of 70
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)