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
Class Reply inherits from class Post. Write the header for class Reply (one line only).
Free
(Short Answer)
4.9/5
(26)
Correct Answer:
public class Reply extends Post
Assume that a PlayerNode class has been coded with the appropriate constructors and the methods setNext, getNext, setPlayer, and getPlayer. The data inside the PlayerNode class is a Player. Assume that a LinkedList class (encapsulating a list of Players) has been coded, and it has a head instance variable as a reference to the first PlayerNode in the list. Write a method inside the LinkedList class that deletes the last item in the list, returns true if this was successful, and returns false otherwise. Assume that your LinkedList class does not include the number of items as an instance variable.
Free
(Essay)
4.8/5
(39)
Correct Answer:
public boolean deleteLast( )
{
if ( head == null )
return false; // empty list
PlayerNode current = head;
PlayerNode previous = null;
while ( current.getNext( ) != null )
{
previous = current;
current = current.getNext( );
}
if ( previous == null ) // one item in list
head = null;
else
previous.setNext( null );
return true;
}
Here is the code for a recursive method for binary search that is searching a sorted array of ints. The array is assumed to be sorted in ascending order.
// we are looking for the value stored in the parameter key
public static int binarySearch ( int [ ] arr, int key, int start,
int end )
{
System.out.println( "Start = " + start + "; end = " + end );
if ( start <= end )
{
int middle = ( start + end ) / 2;
if ( arr[middle] == key ) // found it at index middle
return middle;
else if ( arr[middle] > key ) // look left
return binarySearch( arr, key, start, middle - 1 );
else // look right
return binarySearch( arr, key, middle + 1, end );
}
else // not found
return -1;
}
We are running the following code:
int [ ] numbers = { 4, 6, 8, 10, 11, 12, 14, 16, 18 };
int found = binarySearch( numbers, 10, 0, 8 );
What is the output? Show what the output statement in the binarySearch method outputs. The question is not about the value of found; the value of found is 3.
Free
(Essay)
4.9/5
(30)
Correct Answer:
Start = 0; end = 8
Start = 0; end = 3
Start = 2; end = 3
Start = 3; end = 3
Place the following steps required to calculate a minimum value in the correct order.
-Identify a new current minimum if its value is less than previous minimum.
(Short Answer)
4.8/5
(35)
Write a complete program. Prompt the user for two integers (using Scanner). Assume that the user will enter two well-formatted integers. You do not have to check for that. They should both be greater than or equal to 0 and the first one must be strictly less than the second one; if this is not the case, output WRONG DATA. If that is the case, calculate the exact ratio of the first number divided by the second number (for example, if the numbers are 6 and 10, the ratio is 0.6; if the numbers are 4 and 10, the ratio is 0.4). If that ratio is strictly greater than 0.5, output ABOVE AVERAGE; if it is equal to 0.5 (do not worry about possible rounding errors), output AVERAGE; if it is less than 0.5, output BELOW AVERAGE.
(Essay)
4.8/5
(37)
Complete the code, drawing three more lines using the current stroke color to complete a square between the points (100, 100) and (300, 300).
// gc is a GraphicsContext reference
gc.strokeLine( 100, 100, 300, 100 );
// your code goes here
(Essay)
4.8/5
(31)
Give the values that are assigned to each variable after the statements below are executed.
-double i = ( double ) ( 6 / 4 ); __________
(Short Answer)
4.7/5
(40)
Assume that a PlayerNode class has been coded with the appropriate constructors and the methods setNext, getNext, setPlayer, and getPlayer. The data inside the PlayerNode class is a Player. Assume that a LinkedList class (encapsulating a list of Players) has been coded, and has a head instance variable as a reference to the first PlayerNode in the list. Write a method inside the LinkedList class that outputs every other Player in the list, starting with the first one. Assume that your LinkedList class does not include the number of items as an instance variable.
(Essay)
4.9/5
(40)
Inside the main method, prompt the user to enter a word that does not contain a Y until the user enters one.
(Essay)
4.9/5
(43)
Assuming a and b are int variables, apply one of DeMorgan's laws to create an equivalent expression for the following boolean expression:
!( a > 8 && b < 19 )
(Short Answer)
4.8/5
(35)
Complete the code, drawing two non-solid concentric circles (with the current fill color, whatever it is) so that their diameters are 200 and 100 and the coordinates of their center are (250, 150).
// gc is a GraphicsContext reference
// your code goes here
(Essay)
4.8/5
(35)
Complete this code. Assume that you have created a budget and have set your maximum daily spending to $30. Assume that the appropriate classes have been imported.
public static void main( String [] args )
{
//***** 1. define the maximum daily budget as a constant
//***** 2. Instantiate (create) a Scanner object.
//***** 3. Input the amount actually spent today.
//***** 4. Using an if/else statement, tell the user how their
// actual spending compares with their maximum daily budget
// (more, less, or the same?)
}
(Essay)
4.9/5
(36)
Code a recursive method that takes a String as its only parameter and returns a String that is the same as the parameter String except that the first A has been replaced by a B (the first A, not all of the As). If an A is not in the parameter String, then the same String is returned.
(Essay)
4.7/5
(36)
A method is coded as follows:
public static int foo( int n )
{
if ( n <= 0 )
return 0;
else
return ( foo( n - 1 ) + foo( n - 1 ) );
}
What is the running time of this method? Show your work.
(Essay)
4.8/5
(34)
Inside the main method, prompt the user to enter a word that contains a Z until the user enters one.
(Essay)
4.8/5
(34)
In the code below, how many times will EXAM be printed?
for ( int i = 0; i < 5; i++ )
{
for ( int j = 0; j < 10; j++ )
{
System.out.println( "EXAM" );
}
}
(Short Answer)
4.8/5
(37)
Here is an example of a stack of integers represented by an array of five elements:
A. How many elements are on the stack?
B. Show the stack after attempting to pop three times from the stack. Be sure to give the value of top.

(Essay)
4.8/5
(42)
The class Ticket has been coded as follows. Write the mutators (setPrice and setService methods) for the Ticket class. The price must be greater than or equal to 0. The service must be either A or B; the default service is B.
public class Ticket
{
private double price;
private char service;
public Ticket( double newPrice, char newService )
{
setPrice( newPrice );
setService( newService );
}
}
(Essay)
4.7/5
(26)
Showing 1 - 20 of 110
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)