Exam 16: RGB Colors, Decimal Conversion, Java Naming, and Random Number Generation

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

A String variable named s has been declared and holds some value. Output the number of characters in s.

(Essay)
4.7/5
(39)

Complete the code, drawing a solid circle (with the current fill color, whatever it is) so that its diameter is 200 and the coordinates of its center are (250, 150). // gc is a GraphicsContext reference // your code goes here

(Short Answer)
4.9/5
(41)

In the RGB color system, there are 256 possible values for each color (red, green, and blue); a color is considered gray when its red, green, and blue values are identical. How many shades of gray are there (excluding black and white)?

(Short Answer)
4.7/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 Instantiate the HBox bottomBox and set the spacing inside it to 10 pixels. You can use an HBox constructor accepting one parameter; it has the following API: HBox( double spacing )

(Short Answer)
4.7/5
(36)

Give the values that are assigned to each variable after the statements below are executed. -int b = 8 % 3; __________

(Short Answer)
4.8/5
(36)

Convert the String input below to an int and display 4 times that value. Do not hard code either 7 or 28; assume that you do not know the value of input. String input = "7";

(Essay)
4.8/5
(30)

Complete this code in main to perform the requested operations for a date entered by the user in this format: month dd, yyyy. public static void main( String [] args ) { Scanner scan = new Scanner( System.in ); System.out.print( "Enter a date > " ); String date = scan.nextLine( ); Output the first letter in the month. Output the date in all lowercase letters. Output the year portion of the date-that is, the characters in the date that follow the comma. For example, if the date is February 24, 2016, you would output 2016. (Note: Your code should work for ANY date in that format.)

(Essay)
4.9/5
(43)

Consider the following two-dimensional array: String [ ][ ] states = { { "CA", "CO" }, { "MD", "IL", "ME", "MI" }, { "NY", "NJ", "NE" } }; What is the value of states[2][1]? Retrieve ME from the array states and assign it to a String variable of your choice. Using a loop, output all the states that start with the letter M in the second row (as in this example). Assume that you do not know how many columns are in the second row, i.e., do not hard code 4. Assume that you do not know that the three states are MD, ME, and MI.

(Essay)
4.9/5
(48)

List three programming languages and an application for each.

(Essay)
4.8/5
(37)

We have coded class ABC and it has the following constructor: public ABC( String s ) throws SQLException // SQLException is a checked exception Inside the main method, write a minimum valid code sequence using the constructor above; do not worry about import statements.

(Essay)
4.7/5
(35)

Give the values that are assigned to each variable after the statements below are executed. -double c = 3 / 7; __________

(Short Answer)
4.8/5
(47)

Where is the error in the following code sequence, and why? How would you correct it? float number = 6; double d = number; number = 19.7;

(Essay)
4.9/5
(36)

The class Ticket has been coded as follows. Code a method that switches the value of service: if it is A, it changes to B; if it is B, it changes to A. public class Ticket { private double price; private char service; public Ticket( double newPrice, char newService ) { setPrice( newPrice ); setService( newService ); } }

(Essay)
4.9/5
(29)

The file numbers.txt contains only positive integers. We want to calculate the maximum value among them. Complete the code below. int max = 0; try { Scanner scan = new Scanner( new File( "numbers.txt" ) ); // Your code goes here scan.close( ); } catch( Exception e ) { } System.out.println( "max = " + max );

(Essay)
4.9/5
(39)

In the RGB color system, there are 256 possible values for each color (red, green, and blue). A color is considered gray when its red, green, and blue values are identical. There are __________ shades of gray (excluding black and white).

(Short Answer)
4.8/5
(38)

Inside the main method, prompt the user to enter a word that has at least five characters until the user does. After that, count how many times the letter A is in that word and output the result. Example 1: Enter a word > Helo Enter a word > BLABLA Number of As is 2 Example 2: Enter a word > Hi Enter a word > Mid Enter a word > PROGRAMMINGEXAMJAVA Number of As is 4

(Essay)
4.8/5
(47)

Write a statement to define each of the following variables using Java naming conventions: A. A variable named percent that holds the value .023 B. A constant that will hold the number of inches in a foot (12 ). C. A single character that stores the letter A.

(Essay)
4.9/5
(39)

Give the values that are assigned to each variable after the statements below are executed. -int f = 3; f += 10; __________

(Short Answer)
5.0/5
(33)

An array, numbers, has been declared and initialized as follows: int [ ] numbers = { 45, 78, 99, 12, 66 }; What is the index of 78? What is the array element at index 4? Change the array so that we have value 77 instead of 99. Swap the value at indexes 1 and 2 without knowing what the values are. Using a loop, assume that you do not know how many elements are in the array and increase all the values of numbers by 10. Using a loop, assume that you do not know how many elements are in the array and what they are, and calculate and output the number of elements that are strictly greater than 50. Using a loop, assume that you do not know how many elements are in the array and output every other element of the array, starting at the first element.

(Essay)
4.8/5
(38)

A method is coded as follows: public static int foo( int n ) { if ( n < 0 ) return 0; else return ( 2 * foo( n - 10 ) ); } What is the running time of this method? Show your work.

(Essay)
4.8/5
(31)
Showing 81 - 100 of 110
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)