Exam 16: RGB Colors, Decimal Conversion, Java Naming, and Random Number Generation
Exam 1: Introduction to Programming and the Java Language47 Questions
Exam 2: Programming Building Blocks- Java Basics57 Questions
Exam 3: Object-Oriented Programming, Part 1: Using Classes62 Questions
Exam 4: Introduction to Graphical Applications57 Questions
Exam 5: Flow of Control, Part 1: Selection68 Questions
Exam 6: Flow of Control, Part 2: Looping67 Questions
Exam 7: Object-Oriented Programming, Part 2: User-Defined Classes78 Questions
Exam 8: Single-Dimensional Arrays63 Questions
Exam 9: Multidimensional Arrays and the Arraylist Class62 Questions
Exam 10: Object-Oriented Programming, Part 3: Inheritance, Polymorphism, and Interfaces61 Questions
Exam 11: Exceptions, and Input Output Operations77 Questions
Exam 12: Graphical User Interfaces Using Java FX89 Questions
Exam 13: Recursion59 Questions
Exam 14: An Introduction to Data Structures69 Questions
Exam 15: Running Time Analysis56 Questions
Exam 16: RGB Colors, Decimal Conversion, Java Naming, and Random Number Generation110 Questions
Select questions type
The class Ticket has been coded as follows:
public class Ticket
{
private double price;
private char service;
public Ticket( double newPrice, char newService )
{
setPrice( newPrice );
setService( newService );
}
}
What is the data type of the parameter and the return type of the tax method?
public double tax( float rate )
(Short Answer)
4.9/5
(40)
Identify whether each of the following problems is a result of a missing priming read or missing update read.
A. The first time the while loop condition is evaluated, the result is unpredictable.
B. When the sentinel value is read and processed, it produces incorrect results.
C. The while loop continuously processes the same data item, leading to an endless loop.
(Essay)
5.0/5
(28)
Write the code to compute and output how many times the value 99 is found in an array of integers named numbers.
(Essay)
4.9/5
(34)
A String variable named s has been declared and holds some value. If its number of characters is even, output EVEN; otherwise, output ODD.
(Essay)
4.7/5
(40)
Complete the code, drawing a solid cyan figure with its vertices at the points (100, 125), (150, 200), (100, 300), and (350, 350); note that the Color class includes a constant for cyan.
// gc is a GraphicsContext reference
// your code goes here
(Essay)
4.7/5
(45)
Assume that we have already declared a String named email. We want to assign a boolean value to a variable named result2 such that if email has 10 characters or more and its first character is A, then result2 is true; otherwise, result2 is false.
boolean result2;
// your code goes here
(Essay)
4.8/5
(39)
Call the default constructor of BorderPane and consider the following code:
import javafx.scene.control.*;
import javafx.scene.layout.*;
public class BoardGame extends BorderPane
{
private Button one, two;
private HBox bottomBox;
private Label topLabel;
public BoardGame( )
{
// you are coding inside the BoardGame constructor
(Short Answer)
4.8/5
(37)
Consider the following class:
public class Radio
{
private double frequency;
private String name;
// overloaded constructor
// accessors (get methods)
// mutators (set methods)
// other methods
}
Code the two mutators. Frequency must be between 80 and 110 included. If the parameter is out of that range, set the frequency to 100. There is no constraint on name. The mutators should return the Radio reference that calls them.
// Your code goes here
(Essay)
4.9/5
(31)
Consider the following class:
public class Radio
{
private double frequency;
private String name;
// overloaded constructor
// accessors (get methods)
// mutators (set methods)
// other methods
}
Code the overloaded constructor. Call the mutators (set methods) to enforce constraints. Assume that they have been coded correctly.
// Your code goes here
(Essay)
4.9/5
(34)
The variable cities is an ArrayList of type String, Write the code to output all its elements.
(Essay)
4.9/5
(26)
Consider the following source code. What should you name the save file for this source code?
public class SpringBreak
{
// lots of code here
}
(Short Answer)
4.9/5
(31)
Write a Java statement to calculate the value of this formula. Assume that z, x and n are ints and have been assigned values. Assign the result to a variable of the appropriate type.
_____
√ 3z + x
4 - xn
(Essay)
4.9/5
(38)
The class Ticket has been coded as follows. Write the accessor (getPrice and getService methods) for the Ticket class.
public class Ticket
{
private double price;
private char service;
public Ticket( double newPrice, char newService )
{
setPrice( newPrice );
setService( newService );
}
}
(Essay)
4.7/5
(35)
Consider the following state of a linked list of ints.
BEFORE: 45 9
Assume that a Node class has been coded with the appropriate constructors and the methods setNext, getNext, setData, and getData. The data inside the Node class is an integer. The Node variable current is a reference to the Node containing 45. Write a few statements so that after execution of these statements, 58 and 23 have been added between 45 and 9:
AFTER: 45 58 23 9
(Essay)
4.9/5
(39)
How would you determine which integer data type would be best to use?
(Essay)
4.8/5
(31)
Consider the following code and place bottomBox at the bottom of this BorderPane using the setBottom method.
import javafx.scene.control.*;
import javafx.scene.layout.*;
public class BoardGame extends BorderPane
{
private Button one, two;
private HBox bottomBox;
private Label topLabel;
public BoardGame( )
{
// you are coding inside the BoardGame constructor
(Short Answer)
4.8/5
(34)
Consider the following code; instantiate the buttons one and two with the texts ONE and TWO.
import javafx.scene.control.*;
import javafx.scene.layout.*;
public class BoardGame extends BorderPane
{
private Button one, two;
private HBox bottomBox;
private Label topLabel;
public BoardGame( )
{
// you are coding inside the BoardGame constructor
(Essay)
4.8/5
(31)
The class Ticket has been coded as follows. Code the toString method so it returns the service and price separated by a : (colon) as in the following examples:
Example 1: B:34.99
Example 2: A:94.99
Example 3: B:44.99
public class Ticket
{
private double price;
private char service;
public Ticket( double newPrice, char newService )
{
setPrice( newPrice );
setService( newService );
}
}
(Essay)
4.9/5
(37)
Consider the following method:
// Assume that n >= 0
public static String decimalToBinary( int n )
{
System.out.println( "n = " + n );
if ( n == 0 || n == 1 )
return n + "";
else
return decimalToBinary( n / 2 ) + n % 2;
}
What is the output of the following code?
decimalToBinary( 1 ); // the output, NOT the return value
What is the output of the following code?
decimalToBinary( 6 ); // the output, NOT the return value
What is the output of the following code?
decimalToBinary( 37 ); // the output, NOT the return value
(Essay)
4.8/5
(37)
Here is interface I.
public interface I
{
public abstract void foo( );
}
Class C inherits from interface I. Code class C with a minimal implementation so that it is not abstract and it compiles.
(Essay)
4.9/5
(32)
Showing 21 - 40 of 110
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)