There is a variation of the bubble sort algorithm called a gap sort that, rather than comparing neighboring elements each time through the list, compares elements that are i positions apart, where i...
Write some Java statements that use the String methods indexOf and substring to find the first word in a string. We define word to be a string of characters that does not include whitespace. For...
What changes to the ChangeMaker program in Listing 2.3 are necessary if it also accepts coins for one dollar and half a dollar? Listing 2.3 import java.util.Scanner; public class ChangeMaker { public...
Consider the following fragment of code: if (x > 5) System.out.println("A"); else if (x < 10) System.out.println("B"); else System.out.println("C"); What is displayed if x is a. 4; b. 5; c. 6; d. 9;...
What is the value of each of the following boolean expressions if x is 5,y is 10, and z is 15? a. (x < 5 && y > x) b. (x < 5 || y > x) c. (x > 3 || y < 10 && z == 15) d. (! (x > 3) && x!= z || x + y...
Every profession uses computers today. Use aWeb browser and a search engine like Google to find sites that relate your field of study with computer science or computing or computation. For example,...
Now trace this series of who built on whos work. Who invented the laser printer? One of the winners of the ACM Turing Award (the closest that computer science has to a Nobel Prize) invented a...
You are running a bingo game where you want to tweet the winner of each round of the game.You want to announce the name of who won, and how much they won in dollars. Make a function that takes those...
Create a function like the pyramid function that does the upside-down version. Your function invertedPyramid should also take an input character and print an inverted pyramid.
You have written an essay for school, and it has to be at least five pages long. But your essay is only 4.5 pages long!You decide to use your new Python skills to make your essay longer by spacing...
Write a function to blend two pictures, starting with the top third of the first picture and then blend the two together in the middle third and then show the last third of the second picture. This...
One of the four functions below generated this picture. Which one is it? A. B. C. D. def flip1(picture): allpixels = getPixels(picture) In = len(allpixels)-1 address = In for index in range (0,1n/2):...
One of the below programs that when called like this (with the underscore representing a digit from 1 to 4) generates this output: >>> mixem_("we hold these truths") 'w.e. .h.o.l.d. .t.h.ese truths'...
Write a function to draw a simple face with eyes and a mouth. on a picture.
Write a general crop function that takes a source picture, the start X value, the start Y value, the end X value, and the end Y value. Create and return the new picture and copy just the specified...
Create a CartoonPanel class that takes an array of Pictures and displays the pictures from left to right. It should also have a title and author, and display the title at the top left edge and the...
Write a program that produces the following figure (which vaguely resembles the Seattle Space Needle) as its output using nested for loops. Use a class constant to make it possible to change the size...
Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows: :mmZ\dxZmx]Zpgy The message is...
Write a new class TruncatedDollarFormat that is the same as the class DollarFormat from Listing 6.14, except that it truncates rather than rounds to obtain two digits after the decimal point. When...
Write a Java program called Lanterns that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. ** ***** **** ***** ********* ***** **...
Write a JavaFx application that displays a series of pictures of a person with arms, legs, and of course a head. Use a happy face for the head. Use ovals for the body, arms, and legs. Draw a sequence...
Write a program that plays a simplified dice version of blackjack. Instead of selecting from a deck of cards a 14-sided die is rolled to represent a card. The rules of the game for one round, as...
Write a recursive method that will count the number of vowels in a string. Each time you make a recursive call, use the String method substring to construct a new string consisting of the second...
Add a method bubbleSort to the class ArraySorter, as given in Listing 7.10, that performs a bubble sort of an array. The bubble sort algorithm examines all adjacent pairs of elements in the array...
Add a method insertionSort to the class ArraySorter, as given in Listing 7.10, that performs an insertion sort of an array. To simplify this project, our insertion sort algorithm will use an...
Write a program that shows the total number of presents that the person in the song The Twelve Days of Christmas received on each day, as indicated in Table 3.5. Table 3.5 Twelve Days of Christmas
The class TimeBook in Listing 7.14 is not really finished. Complete the definition of this class in the way described in the text. In particular, be sure to add a default constructor, as well as set...
Write a piece of code that prints an array of integers in reverse order, in the same format as the print method from Section 7.2. Consider putting your code into a method called printBackwards that...
Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The puzzle solver must fill in the squares with the digits 1 to 9 such that no digit is...
Students are often asked to write term papers containing a certain number of words. Counting words in a long paper is a tedious task, but the computer can help. Write a program that counts the number...
Write a constructor for the UndergraduateStudent class that accepts a name as a parameter and initializes the UnderGraduateStudent s state with that name, an age value of 18, and a year value of 0.
Write a program that produces the following figure (which vaguely resembles a textbook) as its output using nested for loops. Use a class constant to make it possible to change the size of the figure...
Write a program that produces as output the words of The Twelve Days of Christmas. (Static methods simplify this task.) Here are the first two verses and the last verse of the song: On the first day...
Write a complete Java program called WellFormed that prints the following output:
Why is recursion an effective way to implement a backtracking algorithm?
For this project, we will create a data structure known as a queue. A queue can be thought of as a line. Items are added at the end of the line and are taken from the front of the line. You will...
What characteristic does Ruby share with Smalltalk?
Write the state of the elements of each of the following arrays after each pass of the outermost loop of the selection sort algorithm has occurred (after each element is selected and moved into...
Write a JavaFX application that uses a text field to get the name of a file, reads the file byte by byte, and displays the bytes as characters. (Exercise 15 describes how to convert a byte value to a...
The following program contains 7 mistakes! What are they? What output is produced for each of the following calls? a. IfElseMystery1(3, 20); b. IfElseMystery1(4, 5); c. IfElseMystery1(5, 5); d....
An element can be inserted at the beginning, middle, or end of an array list. Which of the three insertion points is the most computationally expensive, and why? Which is the most expensive location...
Modify your program from the previous exercise to draw the figure by a method called drawFigure . The method should accept three parameters: the Graphics g of the DrawingPanel on which to draw, and a...
Define ordinal, enumeration, and subrange types.
Analyze and write a comparison of using C++ pointers and Java reference variables to refer to fixed heap- dynamic variables. Use safety and convenience as the primary considerations in the comparison.
Describe three specific programming situations that require a posttest loop.
Write a program that reads a file containing data about the changing popularity of various baby names over time and displays the data about a particular name. Each line of the file stores a name...
Suppose you want to write a method that prints a heading on a new output page, along with a page number that is 1 in the first activation and that increases by 1 with each subsequent activation. Can...
Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date...
Add a transfer method to the BankAccount class from the previous exercises. Your method should move money from the current bank account to another account. The method accepts two parameters: a second...
Write a class named Dodecagon whose objects represent regular dodecagons (12-sided polygons). Your class should implement the Shape interface defined in this chapter. A Dodecagon object is defined by...
How can the parent version of an inherited method that is overridden in a subclass be called in that subclass in C#?
The Sierpinski carpet is a fractal that is defined as follows: The construction of the Sierpinski carpet begins with a square. The square is cut into nine congruent subsquares in a 3-by-3 grid, with...
Write a method called reverse that accepts a map from strings to strings as a parameter and returns a new map that is the reverse of the original. The reverse of a map is a new map that uses the...
Write a program that solves the classic stable marriage problem. This problem deals with a group of men and a group of women. The program tries to pair them up so as to generate as many stable...
A URL is a type of _________. a. Web page b. URI c. Link d. Network
To which complexity class does the following algorithm belong? public static void mystery2 (int [] list) { for (int i = 0; i < list.length / 2; i++) { int j = list.length 1 i; int temp = list[i];...
To which complexity class does the following algorithm belong? public static void mystery4 (List list) { for (int i = 0; i < list.size () 1; i += 2) { %3D String first list.get (i); !! list.set (i,...
How would the results of the following two statements differ?
What type of error occurs when the interpreter fails to recognize code? a. Debugging b. Syntax c. Run-time d. Logic
Which API provides access to data from a devices gyroscope and accelerometer? a. Geolocation API b. Battery Status API c. Device Orientation API d. WebRTC API
What number is displayed by this program? Set Number1 = 4 Set Number1 = Number1 + 1 Set Number2 = 3 Set Number2 = Number1 * Number2 Write Number2
Consider the following C program: What is the value of x after the assignment statement in main, assuming a. Operands are evaluated left to right. b. Operands are evaluated right to left. int fun...
The term defensive programming refers to which of the following (select all that apply): a. Ensuring that input data are in the proper range b. Ensuring that a division by 0 does not take place c....
If X = 1 and Y = 2 determine whether each of the following expressions is true or false. (a) T F X >= X OR Y >= X (b) T F X > X AND Y > X (c) T F X > Y OR X > 0 AND Y < 0 (d) T F NOT(NOT(X == 0) AND...
The number N factorial, denoted by N!, is defined to be the product of the first N positive integers: N! = 1 2 . . . N For example: 5! = 1 2 3 4 5 = 120 7! = 1 2 3 4 5 6 7 = 5,040 Find...
Give the output of the loop in Exercise 19. Data from Exercise 19 Declare K As Integer For (K = 3; K
What is the output of the code corresponding to the following pseudocode? Declare I, J As Integer For (I = 1; I
What is the output of the code corresponding to the following pseudocode? Declare HelloCount As Integer Set HelloCount = 1 Repeat Repeat Write "Hello" Until HelloCount >= 1 Set HelloCount =...
The factorial of a positive integer N, denoted by N!, is defined by the following: N! = 1 2 . . . N (Note: 0! = 1 ) Using subprograms and functions, create a recursive program to compute N!. The...
Redo Programming Challenge 6 but use a binary search. Bonus: Add pseudocode to check how many iterations must be made for each number entered by the user, and, if you also complete Programming...
Create a Visual Basic Windows application. Use the following names for the solution and project, respectively: Valley Solution and Valley Project. Save the application in the VB2015\Chap01 folder....
The Internet contains a vast amount of code snippets that you can use in your Visual Basic applications. And in many cases, you can use the snippet without fully understanding each line of its code....
Open the Debug Solution (Debug Solution.sln) file contained in the VB2015\Chap06\ Debug Solution-B15 folder. Open the Code Editor window and review the existing code. Start and then test the...
Modify the HeapIntPriorityQueue class written in this chapter to make it configurable in ways similar to Javas PriorityQueue class. Make it possible for the heap to be a min-heap or max-heap. (If you...
Create an application that displays a circles area and circumference, given its radius. Use the following names for the solution and project, respectively: Circle Solution and Circle Project. Save...
In this exercise, you experiment with procedure-level and class-level variables. Open the VB2015\Chap03\Scope Solution\Scope Solution (Scope Solution.sln) file. The application allows the user to...
Write a method called descending that accepts an array of integers and rearranges the integers in the array to be in descending order using a PriorityQueue as a helper. For example, if the array...
In this exercise, you modify the Net Income or Loss application from Lesson A. Use Windows to make a copy of the Net Solution folder. Rename the copy Net Solution- Print. Open the Net Solution (Net...
Patti Garcia owns two cars, referred to as Car 1 and Car 2. She wants to drive one of the cars to her vacation destination, but shes not sure which one (if any) would cost her the least amount in...
Explain why a class might provide a set method and a get method for an instance variable.
Factorials are used frequently in probability problems. The factorial of a positive integer n (written n! and pronounced n factorial) is equal to the product of the positive integers from 1 to n....
In this exercise, you modify the wedding reception application from Exercise 9. The modified application will display the number of rectangular tables needed to seat the bridal party as well as the...
Write a line of code that performs each of the following tasks: a) Specify that class PieceWorker inherits from class Employee. b) Call superclass Employees toString method from subclass PieceWorkers...
Discuss three proper ways in which you can assign superclass and subclass references to variables of superclass and subclass types.
Modify Solution 2 shown earlier in Figure 6-4. The solution should now keep track of the number of times Sahirahs laser beam missed the spider. After saying You are safe now. The spider is dead.,...
In this exercise, you create an application that displays the name of the artist corresponding to the song title selected in a combo box. Create the application, using the following names for the...
What value is contained in the integer variable size after the following statements are executed?
In this exercise, you learn how to specify that one or more arguments are optional in a Call statement. Open the VB2015\Chap07\Optional Solution\Optional Solution (Optional Solution.sln) file. a....
Show the contents of a queue after the following operations are performed. Assume the queue is initially empty. enqueue(45); enqueue(12); enqueue(28); dequeue(); dequeue(); enqueue(69); enqueue(27);...
Write a method called depthSum that returns the sum of the values stored in a binary tree of integers weighted by the depth of each value. The method should return the value at the root, plus 2 times...
Write a method called removeLeaves that removes the leaves from a tree. A leaf is a node that has empty left and right subtrees. If your method is called on an empty tree, the method does not change...
Write a method called matches that returns a count of the number of nodes in one tree that match nodes in another tree. A match is defined as a pair of nodes that are in the same position in the two...
Write a program that prompts the user to enter an integer between 0 and 15 and displays its corresponding hex number. For an incorrect input number, display invalid input. Here are some sample runs:...
Suppose we have a hash set that uses the standard mod hash function shown in the chapter and uses linear probing for collision resolution. The starting hash table length is 5, and the table chooses...
Write a method called kthSmallest that accepts a PriorityQueue of integers k and an integer as parameters and returns the kth-smallest integer from the priority queue. For example, if the queue...
Write a program that displays all the numbers from 100 to 200 (10 per line) that are divisible by 5 or 6, but not both. Numbers are separated by exactly one space.
Fill in the blanks in each of the following statements: a) Computers process data under the control of sets of instructions called __________. b) The key logical units of the computer are the , , ,,...
What does the following program print? public class Mystery2 { public static void main(String[] args) { int count = 1; while (count
Based on the dangling-else discussion in Exercise 4.27, state the output for each of the following code segments when x is 9 and y is 11 and when x is 11 and y is 9. We eliminated the indentation...
Write a program that moves the ball in a pane. You should define a pane class for displaying the ball and provide the methods for moving the ball left, right, up, and down, as shown in Figure 15.26c....