New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
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
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
java how to program late objects
Java How To Program Late Objects Version 8th Edition Paul Deitel, Deitel & Associates - Solutions
Write an application that reads a five-letter word from the user and produces every possible three-letter string that can be derived from the letters of that word. For example, the three-letter words produced from the word “bathe”include “ate,” “bat,” “bet,” “tab,” “hat,”
String manipulation enables interesting approaches to analyzing the writings of great authors. Much attention has been focused on whether William Shakespeare ever lived.Some scholars believe there’s substantial evidence indicating that Christopher Marlowe actually penned the masterpieces
Dates are printed in several common formats. Two of the more common formats are 04/25/1955 and April 25, 1955 Write an application that reads a date in the first format and prints it in the second format.
Computers are frequently employed in check-writing systems, such as payroll and accounts payable applications. There are many strange stories about weekly paychecks being printed (by mistake) for amounts in excess of $1 million. Incorrect amounts are printed by computerized check-writing systems
Perhaps the most famous of all coding schemes is the Morse code, developed by Samuel Morse in 1832 for use with the telegraph system. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (e.g., period, comma, colon, semicolon).
Write an application that will assist the user with metric conversions. Your application should allow the user to specify the names of the units as strings (i.e., centimeters, liters, grams, and so on, for the metric system and inches, quarts, pounds, and so on, for the English system) and should
Many apps you use daily have built-in spell checkers. In this project, you’re asked to develop your own spell-checker utility. We make suggestions to help get you started. You should then consider adding more capabilities. Use a computerized dictionary (if you have access to one) as a source of
Most people have worked a crossword puzzle, but few have ever attempted to generate one. Generating a crossword puzzle is suggested here as a stringmanipulation project requiring substantial sophistication and effort. There are many issues the programmer must resolve to get even the simplest
Obesity in America is increasing at an alarming rate. Check the map from the Centers for Disease Control and Prevention (CDC) at http://www.cdc.gov/obesity/data/adult.html, which shows obesity trends in the United States over the last 20 years. As obesity increases, so do occurrences of related
Spam (or junk e-mail) costs U.S. organizations billions of dollars a year in spam-prevention software, equipment, network resources, bandwidth, and lost productivity.Research online some of the most common spam e-mail messages and words, and check your own junk e-mail folder. Create a list of 30
Short Message Service (SMS) is a communications service that allows sending text messages of 160 or fewer characters between mobile phones. With the proliferation of mobile-phone use worldwide, SMS is being used in many developing nations for political purposes(e.g., voicing opinions and
It’s possible (and actually common) to have several transaction records with the same record key. This situation occurs, for example, when a customer makes several purchases and cash payments during a business period. Rewrite your accounts receivable file-matching program to provide for the
Recreate your solution for Exercise 15.5 using XML serialization. You may want to create applications to read the data stored in the .xml files—the code in Section 15.5.2 can be modified for this purpose.Exercise 15.5It’s possible (and actually common) to have several transaction records with
Standard telephone keypads contain the digits zero through nine. The numbers two through nine each have three letters associated with them (Fig. 15.19). Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words
Encryption is the process of encoding messages in order to prevent unauthorized parties from reading them. The reverse operation is decryption which aims to restore the original messages. The Caesar cipher is a simple encryption algorithm that replaces each letter in a message with a letter further
Phishing is a form of identity theft in which, in an e-mail, a sender posing as a trustworthy source attempts to acquire private information, such as your user names, passwords, credit-card numbers and social security number. Phishing e-mails claiming to be from popular banks, credit-card
Briefly answer the following questions:a) What is the primary difference between a Set and a Map?b) What happens when you add a primitive type (e.g., double) value to a collection?c) Can you print all the elements in a collection without using an Iterator? If yes, how?
Explain briefly the operation of each of the following Iterator-related methods:a) Iteratorb) HasNextc) Next
What will happen in the following cases?a) Using BinarySearch with an unsorted list.b) Using an Iterator operation after modifying its related collection.c) Creating an object of HashSet using a list that contains duplicate elements.
Determine whether each of the following statements is true or false. If false, explain why.a) Vectors are synchronized by default.b) Class Stack does not have a method add.c) In order to use the method sort, the elements in the list must implement the Comparable interface.
Rewrite lines 10–25 in Fig. 16.3 to be more concise by using the asList method and the LinkedList constructor that takes a Collection argument.Fig. 16.3 1 // Fig. 16.3: ListTest.java // Lists, LinkedLists and ListIterators. 3 import java.util.List; 4 import java.util.LinkedList; 5 import
Write a program that reads in a series of first names and eliminates duplicates by storing them in a Set. Allow the user to search for a first name.
Write a class AccountComparator to implement the Comparator interface for class Account in Figure 15.9 based on the account’s balance. Use this class in order to sort a list of accounts in descending order based on the accounts’ balance.Figure 15.9 I 2 4 5 6 7 8 9 10 II 12 13 14 15 16 17 18 19
Write an application to implement the three Set operations: interaction, union, and difference. You should build three methods corresponding to the operations. In your main method, test these methods on two HashSets of strings.
Write a program that has a method ListConcatenate which receives two objects of LinkedList, and returns a new LinkedList that contains elements of the first list followed by elements of the second list. In the main method, test this method on two LinkedLists of strings.
Write a program that takes a whole number input from a user and determines whether it’s prime. If the number is not prime, display its unique prime factors. Remember that a prime number’s factors are only 1 and the prime number itself. Every number that’s not prime has a unique prime
Write a program that uses a String method split to tokenize a line of text input by the user and places each token in a TreeSet. Print the elements of the TreeSet.
The output of Fig. 16.14 shows that Priority-Queue orders Double elements in ascending order. Rewrite Fig. 16.14 so that it orders Double elements in descending order (i.e., 9.8 should be the highest-priority element rather than 3.2).Fig. 16.14 1 // Fig. 16.14: PriorityQueueTest.java 2 //
Create a class that mixes two LinkedLists of numbers. Your class should include a static method mixList that takes the references of two LinkedLists as arguments and inserts the numbers in the second list into the first list at alternate positions. For example, if the first list has “3,1,7,4”
Assuming that list is a List, explain in detail the stream pipeline: 1234 4 list.stream() .filter(value .distinct() .count() -> value < 0)
Modify the program of Fig. 17.22 to summarize the number of occurrences of every character in the file.Fig. 17.22 1 // Fig. 17.22: StreamOfLines.java 2 // Counting word occurrences in a text file. 4 3 import java.io.IOException; import java.nio.file.Files; 5 import java.nio.file. Paths; 6 import
How to get informationabout files and directories on disk. In addition, you used a DirectoryStream to display the contents of a directory. Interface DirectoryStream now contains default method entries, which returns a Stream. DirectoryStream method entries, lambdas and streams to summarize the
Use the class Invoice provided in the exercises folder with this chapter’s examples to create an array of Invoice objects. Use the sample data shown in Fig. 17.25. Class Invoice includes four instance variables—a partNumber (type String), a part-Description (type String), a quantity of the item
Write a program to generate ten random integers between zero and a thousand, then display how many of them are odd and how many are even; also display the average of: all numbers, odd numbers, and even numbers.
Write a program that reads phone directory records from a text file. Each line in the text file represents a record composed of a first name, a last name, and a phone number separated by spaces. Your program should remove all duplicate records, and output two new text files:a) A phone directory
Answer the following questions with regard to the stream pipeline in Fig. 17.7:a) How many times does the filter operation call its lambda argument?b) How many times does the map operation call its lambda argument?c) If you reverse the filter and map operations in the stream pipeline, how many
Modify the Stream example that it uses stream capabilities to display the average Employee salary by department.
The example of Fig. 17.7 summed the triples of the even integers from 2 through 10. We used filter and map in the stream pipeline to demonstrate both in one stream pipeline. Reimplement Fig. 17.7’s stream pipeline using only map (similar to Fig. 17.4).Fig. 17.7Fig. 17.4 1 // Fig. 17.7:
Figures 4.8 and 4.10 demonstrated calculating a class average with counter-controlled repetition and sentinel-controlled repetition, respectively. Create a program that reads integer grades and stores them in an ArrayList, then use stream processing to perform the average calculation.Figure
Create a program that reads integer grades and stores them in an ArrayList, then use stream processing to display each grade’s letter equivalent (A, B, C, D or F).Response to comment:I assume it is the normal range. 90-100 A, 80-89 B, 70-79 C, 60-69 D, and below F
Defined a two-dimensional array of grades with 10 rows and three columns, representing 10 students’ grades on three exams. Use a stream pipeline to calculate the average of all the grades. For this exercise, use Stream method of to create a stream from the two-dimensional array and Stream method
Defined a two-dimensional array of grades with 10 rows and three columns, representing 10 students’ grades on three exams. Use streams to calculate the students’ individual averages.
Create a collection of Person objects in which each Person has a firstName and a lastName. Use streams to locate the first Person object containing the last name Jones. Ensure that several Person objects in your collection have that last name.
Use an infinite stream of integers to display the first n prime numbers, where n is input by the user.
In Fig. 17.24, we implemented a stream pipeline that rolled a die 60,000,000 times using values produced by SecureRandom method ints. Package java.time contains types Instant and Duration that you can use to capture the time before and after evaluating the stream pipeline, then calculate the
Write a recursive method that is equivalent to the following iterative method: 1 2 3 4 5 6 int mystery (int x) { int sum = 0; for(int i = x; i > 0; i--) sum = sum + 1; return sum }
What does the following code do? There is a statement after the recursive call which should be executed for each call. I 23456 public void printInt (int n) { if (n != 0) { printInt(n 1); System.out.println(n); } }
Write a recursive method power(base, exponent) that, when called, returns base exponent For example, power(3,4) = 3 * 3 * 3 * 3. Assume that exponent is an integer greater than or equal to 1. The recursion step should use the relationship base exponent = base · base exponent – 1 and the
It’s interesting to watch recursion “in action.” Modify the factorial method in Fig.18.3 to print its local variable and recursive-call parameter. For each recursive call, display the outputs on a separate line and add a level of indentation. Do your utmost to make the outputs clear,
The greatest common divisor of integers x and y is the largest integer that evenly divides into both x and y. Write a recursive method gcd that returns the greatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equal to 0, then gcd(x, y) is x; otherwise,
Euler’s number, e, is the base of the natural logarithm, and is widely used in engineering, science and business. The value of e can be approximated using the formulaWrite a recursive method to calculate Euler’s number for n (where n ≥ 0). 1 c=1+ = + e 2! + 1 + 3! 4! 14+.. + n = 0, 1, 2 ...
A puzzler for chess buffs is the Eight Queens problem, which asks: Is it possible to place eight queens on an empty chessboard so that no queen is “attacking” any other (i.e., no two queens are in the same row, in the same column or along the same diagonal)? For example, if a queen is placed in
Write a recursive method searchArray that searches for an element in an array of integers, and returns its position or -1 if it is not found.
Write a recursive method stringReverse that takes a character array containing a string as an argument and prints the string backward.
Write a recursive method recursiveMinimum that determines the smallest element in an array of integers. The method should return when it receives an array of one element.
Repeat the fractal pattern form a star with several colors. Begin with five lines (see Fig. 18.22 ) instead of one, where each line is a different arm of the star. Apply the “Lo feather fractal” pattern to each arm of the star.Fig. 18.22 mollis
The grid of #s and dots (.) in Fig. 18.23 is a two-dimensional array representation of a maze. The #s represent the walls of the maze, and the dots represent locations in the possible paths through the maze. A move can be made only to a location in the array that contains a dot.Fig. 18.23Write a
Write a method mazeGenerator that takes as an argument a two-dimensional 12-by-12 character array and randomly produces a maze. The method should also provide the starting and ending locations of the maze. Test your method mazeTraversal from Exercise 18.20 , using several randomly generated
Enhance the Fibonacci program of Fig. 18.5 so that it calculates the approximate amount of time required to perform the calculation and the number of calls made to the recursive method. For this purpose, call static System method current-TimeMillis, which takes no arguments and returns the
Using the techniques you learned in Section 18.9, implement an application that draws the Koch Curve. 18.9.1 Koch Curve Fractal As an example, let's look at the strictly self-similar Koch Curve fractal (Fig. 18.12). It's formed by removing the middle third of each line in the drawing and replacing
Research the Koch Snowflake online then, using the techniques you learned in Section 18.9, implement an application that draws the Koch Snowflake. 18.9.1 Koch Curve Fractal As an example, let's look at the strictly self-similar Koch Curve fractal (Fig. 18.12). It's formed by removing the middle
Using the String-processing capabilities, the file and directory capabilities and a Map, create an application that recursively walks a directory structure supplied by the user and reports the number of files of each file type (such as .java, .txt, .class, .docx, etc.) that exist in the specified
Each of the counter-controlled for loops we used in this chapter’s examples can be implemented using IntStream’s rangeClosed method to produce a range of values, then using IntStream’s forEach method to specify a lambda to execute for each value. The lambda argument to forEach could, for
Reimplement the factorial methods of Figs. 18.3 –18.4 to calculate factorials using lambdas and streams, rather than recursion.Fig. 18.3Fig. 18.4 1 // Fig. 18.3: Factorial Calculator.java // Recursive factorial method. 2 3 4 public class Factorial Calculator { 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Reimplement the fibonacci method of Fig. 18.5 to calculate Fibonacci numbers using lambdas and streams, rather than recursion.Fig. 18.5 I // Fig. 18.5: FibonacciCalculator.java // Recursive fibonacci method. import java.math.BigInteger; 23456780 5 public class FibonacciCalculator { 9 10 II 12 13 14
A bucket sort begins with a one-dimensional array of positive integers to be sorted and a two-dimensional array of integers with rows indexed from 0 to 9 and columns indexed from 0 to n – 1, where n is the number of values to be sorted. Each row of the two-dimensional array is referred to as a
Write a method recursiveBubbleSort that uses recursive techniques to perform an ascending bubble sort on an array of integers. The method should receive the array and an integer representing the number of elements not sorted yet. In every iteration, the largest number should move towards the end of
Write a method insertionRecursiveSort that implements an insertion sort using recursive techniques.
The recursive sorting technique called quicksort uses the following basic algorithm for a one-dimensional array of values:a) Partitioning Step: Take the first element of the unsorted array and determine its final location in the sorted array (i.e., all values to the left of the element in the
In earlier chapters, we showed how computers can help improve the learning process. In this chapter, you studied a variety of sorting algorithms. Each has the same goal—to produce a sorted array—but each algorithm operates differently. It’s helpful to use graphics, animation and sound to make
Assuming GClass is a generic class, what is wrong with the following statement:GClass obj = new GClass();
Write a generic method reverseArray that reverses the order of elements in an array. Use this generic method in a program to reverse arrays of different types.Print each array both before and after calling reverseArray using a generic method similar to Fig. 20.3.Fig. 20.3 1 // Fig. 20.3: Generic
Overload generic method printArray of Fig. 20.3 so that it takes two additional integer arguments, lowSubscript and highSubscript. A call to this method prints only the designated portion of the array. Validate lowSubscript and highSubscript.If either is out of range, the overloaded printArray
Overload generic method printArray of Fig. 20.3 with a nongeneric version that specifically prints an array of Strings in neat, tabular format, as shown in the sample output that follows:Fig. 20.3 Array stringArray two six one five contains: three seven four eight
Write a generic class Pair which has two type parameters—F and S—each representing the type of the first and second element of the pair, respectively. Add get and set methods for the first and second elements of the pair. The class header should be public class Pair.
Can a generic method be overloaded with a nongeneric method?
Explain why a Java program might use the statement List workerList = new ArrayList();
Modify the method created in Exercise 5.18 to receive a second parameter of type char called fillCharacter. Form the square using the char provided as an argument. Thus, if side is 5 and fillCharacter is #, the method should displayUse the following statement (in which input is a Scanner object) to
Modify the application you wrote in Exercise 4.24 to read an odd number in the range 1 to 19 to specify the number of rows in the diamond. Your program should then display a diamond of the appropriate size.Exercise 4.24Write an application that prints the following two dimensional matrix. Use for
A criticism of the break statement and the continue statement is that each is unstructured. Actually, these statements can always be replaced by structured statements, although doing so can be awkward. Describe in general how you’d remove any break statement from a loop in a program and replace
What does the following program segment do? -2345678901 for (i = 1; i
Modify Exercise 4.15 to combine your code from the four separate triangles of asterisks such that all four patterns print side by side.Exercise 4.15Write an application that displays the following patterns separately,one below the other. Use for loops to generate the patterns. All asterisks (*)
Write an application that uses iteration and switch statements to print the song “The Twelve Days of Christmas.” One switch statement should be used to print the day (“first,” “second,” and so on). A separate switch statement should be used to print the remainder of each verse. Visit
The controversial issue of global warming has been widely publicized by the film “An Inconvenient Truth,” featuring former Vice President Al Gore. Mr. Gore and a U.N. network of scientists, the Intergovernmental Panel on Climate Change, shared the 2007 Nobel Peace Prize in recognition of
There are many proposals to make taxation fairer. Check out the FairTax initiative in the United States at http://www.fairtax.org. Research how the proposed FairTax works. One suggestion is to eliminate income taxes and most other taxes in favor of a 23% consumption tax on all products and services
For the class Craps in Fig. 5.8, state the scope of each of the following entities:a) the variable randomNumbers.b) the variable die1.c) the method rollDice.d) the method main.e) the variable sumOfDice.Fig. 5.8 I // Fig. 5.8: Craps.java 2 // Craps class simulates the dice game craps. 3 import
Write an application that tests whether the examples of the Math class method calls shown in Fig. 5.2 actually produce the indicated results.Fig. 5.2 Method abs (x) ceil(x) cos(x) exp(x) floor (x) log(x) max (x, y) min(x, y) pow (x, y) sin(x) sqrt (x) tan (x) Description absolute value of x rounds
Find the error in each of the following program segments. Explain how to correct the error.a)b)c)d) Ivoid go { 234567 System.out.println("Inside method g"); void h() { 6 } 7 } System.out.println("Inside method h");
What is the value of x after each of the following statements is executed?a) x = Math.abs(-7.5);b) x = Math.floor(5 + 2.5);c) x = Math.abs(9) + Math.ceil(2.2);d) x = Math.ceil(-5.2);e) x = Math.abs(-5) + Math.abs(4);f) x = Math.ceil(-6.4) - Math.floor (5.2);g) x = Math.ceil(-Math.abs(-3 +
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time.
Math.floor can be used to round values to the nearest integer—e.g.,double y = Math.floor(x + 0.5);will round the number x to the nearest integer and assign the result to y. Write an application that reads double values and uses the preceding statement to round each of the numbers to the nearest
To round numbers to specific decimal places, use a statement like double y = Math.floor(x * 10 + 0.5) / 10;which rounds x to the tenths position (i.e., the first position to the right of the decimal point), or double y = Math.floor(x * 100 + 0.5) / 100;which rounds x to the hundredths position
Write statements that assign random integers to the variable n in the following ranges: a) 2n 6. b) 4 n 50. c) 0 < n 7. 1000 n 1030. d) e) -5 n 1. f) -2 n9.
Write statements that will display a random number from each of the following sets:a) 0, 3, 6, 9, 12.b) 1, 2, 4, 8, 16, 32.c) 10, 20, 30, 40.
Write two methods myFloor and myCeil that take a positive double num variable int myFloor(double num) and int myCeil(double num). The myFloor method takes num and returns the largest integer number that is less than or equal to x. The myCeil function takes num and finds the smallest number that is
Define a method hypotenuse that calculates the hypotenuse of a right triangle when the lengths of the other two sides are given. The method should take two arguments of type double and return the hypotenuse as a double. Incorporate this method into an application that reads values for side1 and
Write a method isMultiple that determines, for a pair of integers, whether the second integer is a multiple of the first. The method should take two integer arguments and return true if the second is a multiple of the first and false otherwise. Incorporate this method into an application that
Write a method isDivisible that uses the remainder operator (%) to determine whether ten input integers are divisible by 5 or not. The method should take an integer argument and return true if the integer is divisible by 5 and false otherwise. Incorporate this method into an application that inputs
Write a method squareOfAsterisks that displays a solid square (the same number of rows and columns) of asterisks whose side is specified in integer parameter side. For example, if side is 4, the method should displayIncorporate this method into an application that reads an integer value for side
Write an application that prompts the user to enter an year and uses a method called isLeapYear to check whether it is a leap year.
Showing 200 - 300
of 421
1
2
3
4
5
Step by Step Answers