All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to programming with java a problem solving approach
Questions and Answers of
Introduction To Programming With Java A Problem Solving Approach
Assume an ordinary queue has been declared with the Queue interface and instantiated with the ArrayDeque class. Also, assume a priority queue has been declared with the Queue interface and
A collection like ArrayList students could contain two or more references to the same object (same student enrolled in more than one course). Therefore, students.size() would not necessarily return
In the ListExecutionTimes program, the getIndices method fills an ArrayList with randomly ordered indices and then copies the ArrayList’s values to an array. Write code for an alternative
Enhance the HungerGames program. Create a Tribute class with three instance variables, name (a String), district (an int), and gender (a char). Provide this new Tribute class with a constructor to
Modify the Community program by enabling the user to explore alternate community relationships. Specifically, modify the Community constructor so it asks the user to supply an integer seed number.
Fill in the blank: “A recursive method needs to have at least one parameter whose value ________ with successive methods calls.”
When a stopping condition is satisfied, a recursive method calls itself. (T / F)
Write a sufficient stopping condition for the recursive calculation of a factorial.
In Figure 11.2’s factorial calculation, during the calling sequence (before reaching the stopping condition), what is the value of nF when n equals 2?Figure 11.2 1234 4 5 6 7 8 9 10 11 12 13 14 15
Fill in the blank: “If the method’s body includes two recursive calls to itself and the method executes both calls, the method is said to exhibit________.”
If it’s just as easy to solve a problem with a loop as with recursion, which solution is preferable and why?
In the printReverseMessage method of Figure 11.7, what variable changes as the recursion progresses, and what is the stopping condition?Figure 11.7 private static void print Reverse Message(String
Write the recurrence relation for a factorial using the functional notation, f(x).
What’s wrong with the stopping condition in this specification? f(x) [ f(x X-2 - 2) + X x > 0 0 X =
How many recursive method calls does it take to binary search an array with a length of 1,000?
Because a recursive binary search uses tail recursion, it’s easy to convert it to a loop solution. (T / F)
The recursive merge sort algorithm uses binary recursion. (T / F)
In a recursive merge sort, what is the recursive stopping condition?
In a merge sort, the next element to go into the merged array is the smaller of the smallest elements in the two subordinate arrays. What happens when one of the two subordinate arrays becomes empty?
What is the algorithm used to move a stack of disks whose bottom disk is an arbitrary disk n?
Describe the arguments used for the first recursive method call in the algorithm in question 15 in terms of the current method’s parameters.Question 15:What is the algorithm used to move a stack of
What is a fractal?
In our tree-drawing program, what does the model do?
In our tree-drawing program, what does the view do?
In our tree-drawing program, what does the controller do?
The text says: “The else body should contain one or more calls to the same method with argument values that are closer to the stopping condition’s value.” But in the previous section’s
What is wrong with this recursive method? long sum(long n) { return n + sum(n+1);
Many times, you have used Scanner methods to read and parse keyboard input. You can also use those same Scanner methods to read and parse an ordinary string. The following program uses the Scanner
Modify the previous exercise’s Recurse program so that it uses tail recursion. Minimize code changes. You should be able to do this with exactly the same number and sequence of statements and with
Modify the previous exercise’s program so that it uses iteration instead of recursion. Do not use an array.Exercise 11.5:Modify the previous exercise’s Recurse program so that it uses tail
Change Figure 11.2’s recursive Factorial program so that it uses tail recursion.Figure 11.2 1234 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import
A palindrome is a string that reads the same in both directions. For example, “mom,” “kayak,” and “avid diva” are all palindromes. Write a recursive method named isPalindrome that
What’s wrong with this method? public double sum (double x) { if (x >= 0.5) { return x; } else { return sum(x)+ Math.random(); } } // end sum
Given this recurrence relation and stopping condition:By hand, evaluate y(3, 0.1), using the format presented. y(k, A) = (1 + A) - A * y(k-1, A) k > k
Provide a three-parameter tail-recursive static method named fibonacci that generates the numbers in a Fibonacci sequence. It should be an overloaded variation of the one-parameter fibonacci method
The following recurrence relation is called the Logistic Equation:y(k) = y(k-1) + gain * y(k-1) * (1.0 - y(k-1))This is the equation used to simulate growth in the optional problem-solving. This
Specify all changes required to make this chapter’s binarySearch method search for a particular string in an array of String values.binarySearch Method:
Modify this chapter’s MergeSort class to make it sort the strings in an array of String values.MergeSort Class:
Modify the Towers of Hanoi program to help identify its algorithm efficiency. Declare a static variable named moveCount that keeps track of the total number of moves. Remove (or comment out) all the
For each integer data type, how many bits of storage are used?
How would you write the decimal constant, 1.602 × 10−19, as a double?
What is the approximate precision (number of accurate decimal digits) of each of the floating-point types?
How many distinct characters are identified by the basic ASCII character set?
What number can you add to an uppercase-letter char variable to convert it to lowercase?
Assume the declaration:public final double C = 3.0E10; // speed of light in cm/sec Write a Java print statement that uses a cast operator to display the value of C in this format:30000000000.
Will this statement be OK, or will it generate a compile-time error? (OK / error)float price = 66;
Will this statement be OK, or will it generate a compile-time error? (OK / error)boolean done = (boolean) 0;
Will this statement be OK, or will it generate a compile-time error? (OK / error)float price = 98.1;
What is the value of z after these statements execute? int z, x = 3;z = --x;z += x--;
Write one Java statement that makes w, x, and y all equal to the current value of z.
Suppose x equals 0.43. Given the following switch construct heading, what does the controlling expression evaluate to?switch (x>0.67 ? 'H' : (x>0.33 ? 'M' : 'L')).
Assume this:int a = 2; int b = 6;float x = 8.0f;Evaluate each of the following expressions, using these guidelines:• Put each evaluation step on a separate line and use the ⇒ symbol between
Assume expr1 and expr2 are expressions that evaluate to boolean values. Assume that expr1 evaluates to true. When the computer evaluates each of the following expressions, will it evaluate expr2? If
Assume this:int a = 2;boolean flag = true;Evaluate the following expression: a < 3 || flag && !flag.
Assume that the following code fragment is inside of a program that compiles successfully. What does the code fragment print? This is a trick question. Study the code carefully. int x = 1; while (x <
Usually, you should avoid using break statements in loops because using break statements forces readers to look for termination conditions inside loop bodies. (T / F)
Assume that the following code fragment is inside of a program that compiles successfully. What does the code fragment print? for (int i=0, j=0; ; i++, j++) { } System.out.print(i + j + " ") ;
Declare a set of private constants called “Kingdom” that identify the five kingdoms of life: Monera, Protoctista, Fungi, Plantae, and Animalia.
What is the hexadecimal symbol for the decimal number 13?
The Unicode values for characters are the same as the ASCII values in the range 0x00 to 0xFF. (T / F)
If a double value overflows, what happens? What happens if a program divides by the result? Is an error produced, and if so what type of error?
The following program illustrates using BigInteger and BigDecimal. Replace the lines with two assignment statements. As indicated by the output, the first assignment statement divides the original
Provide a robust method named getOddDigit which prompts the user to enter an odd digit and returns the odd digit as an int. Read the input as a string and verify that the input consists of a single
Provide a program that reads a line of text, retrieves the first character from the input line, and displays the subsequent character in the ASCII table.
Assume c and d are boolean variables initialized as false. What are their values after this statement executes?c = !((c=!(7=6));
Assume this:What is the value of the result after this statement executes? int result = flag ? x : (int) (y - 0.7); boolean flag int x = -3; double y = 5.0; false;
Assume this: int a = 4;int b = 13;double x = -9.1;Evaluate each of the following expressions. Follow these guidelines:• Put each evaluation step on a separate line and use the ⇒ symbol between
Assume this:Evaluate each of the following expressions. Follow these guidelines:Put each evaluation step on a separate line and• Use the ⇒ symbol between steps.• Evaluate each expression
Consider the following code fragment. Line numbers are at the left.Trace the code using this trace setup:Does short-circuit evaluation occur in line 4? Why or why not? 2 3 4 5 6 7 int x = 5; boolean
Assume:Determine the output of this code fragment: boolean x; boolean y false; double z 9.5;
What happens if you try to compile the following code, and why does it happen? public static void main(String[] args) { } int number = 4; int factorial = } 1; for (int i=1; i
The Fibonacci sequence is a sequence of numbers such that the first two numbers are 0 and 1, and each successive number is the sum of the two previous numbers. Thus, here are the first nine numbers
The following program works, but it’s ugly. Modify it to perform the same function with a more conventional while loop. import java.util.Scanner; public class Test { public static void
As you learned earlier, an enumerated type is a class (albeit a special kind of class). As such, you can add a main method to it and have that main method run the enumerated type as a program.
Improve the CityTravel program by prompting the user to enter origin and destination cities and using the user-entered values in the getDistance method call. If the user does not spell one of the
Modify the StockAverage2 program in Figure 12.13 by inserting into the stream’s method-call chain a .peek method call that prints the previously entered values. Use a lambda expression for peek’s
What is the Unicode hexadecimal value for Σ (uppercase Greek sigma)? Show or explain how you got your answer.
Run GridWorld’s BugRunner program. Perform the following operations and answer the questions:a) Move the rock to the location of the bug. Then move the rock to location (6, 0).What happens when
In a UML diagram, what does an asterisk (*) indicate?UML diagram: Commission +COMMISSION_RATE: double = 0.10 +addSales(sales: double): void Commissioned -sales: double = 0.0 +Commissioned(name:
In a UML diagram, what does a solid diamond indicate?UML diagram Commission +COMMISSION_RATE: double = 0.10 +addSales(sales: double): void Commissioned -sales: double = 0.0 +Commissioned(name:
Explain how using an inheritance hierarchy can lead to code reusability.
What are two synonyms for a superclass?
What are two synonyms for a subclass?
How do you tell the compiler that a particular class is derived from another class?
Based on the UML diagram in Figure 13.9, an instance of the PartTime class includes the following instance variables: name and id. (T / F)Figure 13.9 Employee Person -name : String +Person()
In a subclass’s constructor, what do you have to do if you want to begin the constructor with a call to the superclass’s zero-parameter constructor?
If a superclass and a subclass define methods having the same name and the same sequence of parameter types, and an object of the subclass calls the method without specifying which version, Java
If a subclass method overrides a method in the superclass, is it still possible to call the method in the superclass from the subclass?
If a superclass declares a variable to be private, can you access it directly from a subclass?
If you wish to call a superclass method, you must always prefix the method name with super. (T / F)
A final method is called “final” because it’s allowed to contain only named constants, not regular variables. (T / F)
Composition and inheritance are alternative programming techniques for representing what is essentially the same kind of real-world relationship. (T / F).
A Deck is a group of cards and a Deck has a group of cards. In our example, it’s better to choose the is-a relationship and implement inheritance. In this case, why is inheritance a better choice
It’s possible to support an association with references, variables, and methods in existing classes. What’s the advantage of using an association class instead?
This exercise should be used in combination with Exercises 2 and 3. Implement a Point class with the following features. Declare a position instance variable—an array of doubles that holds the
This exercise should be used in conjunction with Exercises 1 and 3. Implement a Sphere class with the following features. Declare two instance variables—center (whose type is Point) and radius
This exercise should be used in conjunction with Exercises 1 and 2. Implement a SphereDriver class with a main method that performs the following tasks. Instantiate a Point at x=10, y=15, and z=20.
Suppose that you have three classes—HomeInsurance (insurance for a home), InsurancePolicy (insurance for anything), and FloodDamageInsurance (insurance for flood damage to a home). Assume that the
Suppose you want to design a program that handles various renewable energy sources. Implement your design as a UML diagram with 4 classes (RenewableEnergy, Hydro, Wind, and Solar) and 10 variables
CircleProperties program:Java’s API classes make extensive use of inheritance. For example, Oracle’s Java API documentation shows that the javafx.scene.shape package has a class named Circle that
Showing 200 - 300
of 717
1
2
3
4
5
6
7
8