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 file data.txt contains ABC before the code below is executed: What does data.txt contain after the code below is executed, assuming that the file is found?
try
{
FileOutputStream fos = new FileOutputStream( "data.txt", true );
PrintWriter pw = new PrintWriter( fos );
pw.println( "\nDEF" );
pw.close( );
}
catch( FileNotFoundException fnfe )
{
System.out.println( "GHI" );
}
(Short Answer)
4.9/5
(36)
In the RGB color system, there are 256 possible values for each color (red, green, and blue). How many possible colors are there?
(Short Answer)
4.8/5
(40)
Assume that we have already declared an int named number and a char named letter. We want to assign a boolean value to a variable named result1 such that if number is equal to 100 and letter is equal to A, then result1 is true; otherwise, result1 is false.
boolean result1;
// your code goes here
(Essay)
4.8/5
(41)
Convert 403 into a binary number, and then into a hexadecimal number.
(Essay)
4.9/5
(35)
Give the 4-digit hexadecimal Unicode value for the character '&'. (You can refer to Appendix C.)
(Short Answer)
4.9/5
(37)
The file data.txt contains names. Converting the file data.txt into a Stream, compute and output how many names are in data.txt.
try
{
// Your code goes here
}
catch ( InvalidPathException ipe )
{
System.out.println( ipe.getMessage( ) );
}
catch ( IOException ioe )
{
System.out.println( "Could not find file: " + ioe.getMessage( ) );
}
catch ( SecurityException se )
{
System.out.println( se.getMessage( ) );
}
(Essay)
4.9/5
(39)
Place the following steps required to calculate a minimum value in the correct order.
-Assume the first value read is the minimum.
(Short Answer)
4.8/5
(39)
Consider the following state of a linked list of ints.
BEFORE: 45 58 23 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 9 have been deleted from the list:
AFTER: 45 23
(Essay)
4.9/5
(46)
An algorithm has the following formula for its running time:
T(n) = T(n / 4) + 2
T(1) = 1
What is the running time of the algorithm in Big-Oh notation? Show your work.
(Essay)
4.8/5
(38)
What is the output of the following code sequence?
// parseInt method API (in Integer class)
//public static int parseInt(String) throws NumberFormatException
try
{
int age = Integer.parseInt( "h32" );
}
catch( NumberFormatException nfe )
{
System.out.println( "Hello" );
}
catch( Exception e )
{
System.out.println( "Hi" );
}
finally
{
System.out.println( "Bye" );
}
(Short Answer)
4.7/5
(26)
Complete the code, changing the fill color of the GraphicsContext reference gc to a color with red = 100, green = 200, and blue = 60.
// gc is a GraphicsContext reference
// your code goes here
(Essay)
4.7/5
(35)
Class Rectangle inherits from class Shape and interfaces Colors and Constants. Write the header for class Rectangle (one line only).
(Essay)
4.8/5
(23)
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 );
}
}
In a client class and inside the main method, myTicket is an object reference of type Ticket. Call the method tax with myTicket, assuming a tax rate of 0.06, and assign the resulting tax value to a variable named myTax.
float taxRate = 0.06f;
// Your code goes here
(Short Answer)
4.9/5
(39)
Here is the code for selection sort (for an array of ints):
public static void selectionSort( int [ ] arr )
{
int temp;
int max;
for ( int i = 0; i < arr.length - 1; i++ )
{
max = indexOfLargestElement( arr, arr.length - i );
System.out.println( "max = " + max );
temp = arr[max];
arr[max] = arr[arr.length - i - 1];
arr[arr.length - i - 1] = temp;
}
}
public static int indexOfLargestElement( int [ ] arr, int size )
{
int index = 0;
for ( int i = 1; i < size; i++ )
{
if ( arr[i] > arr[index] )
index = i;
}
return index;
}
We are running the following code:
int [ ] numbers = { 10, 6, 4, 8 };
selectionSort( numbers );
Show what the output statement in the selectionSort method outputs. The question is not what the array looks like at the end; we know it is sorted in ascending order.
(Short Answer)
4.9/5
(34)
Code a recursive method that counts how many times the value 100 is found in an array of integers. Write one statement showing how to use it.
(Essay)
4.9/5
(37)
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
Assuming that the four previous steps have already taken place, add the buttons one and two to bottomBox. To add nodes to an HBox, we must first retrieve its children by calling its getChildren method, then call addAll, passing the list of nodes to add. These two methods have the following API:
In Class Pane (superclass of HBox): ObservableList getChildren( )
In Class ObservableList: boolean addAll( E... elements )
(Short Answer)
4.9/5
(30)
A String variable named s has been declared and holds some value. If s contains the String MIDTERM or FINAL, output EXAM; otherwise, output LECTURE.
(Essay)
4.8/5
(32)
Give the values that are assigned to each variable after the statements below are executed.
-double d = 10.0 / 3; __________
(Short Answer)
4.9/5
(34)
Showing 41 - 60 of 110
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)