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 java programming and data structure
Questions and Answers of
Introduction to Java Programming and Data Structure
The 24-point card game is to pick any four cards from 52 cards, as shown in Figure 20.19. Note the Jokers are excluded.Each card represents a number. An Ace, King, Queen, and Jack represent 1, 13,
A Java program contains various pairs of grouping symbols, such as:■ Parentheses: ( and )■ Braces: { and }■ Brackets: [ and ]Note the grouping symbols cannot overlap. For example, (a{b)} is
Write a program that meets the following requirements. Randomly create 100 points using Point2D and apply the Arrays.sort(list, Comparator) method to sort the points in increasing order of their
Use the Complex class introduced in Programming Exercise 13.17 to develop the ComplexMatrix class for performing matrix operations involving complex numbers. The ComplexMatrix class should extend the
Implement the following method that returns the maximum element in an array:public static > E max(E[] list)Write a test program that prompts the user to enter 10 integers, invokes this method to
In Listing 19.1, GenericStack is implemented using composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the classes then implement GenericStack. Write a test program
The Knight’s Tour is an ancient puzzle. The objective is to move a knight, starting from any square on a chessboard, to every other square once, as shown in Figure 18.15a. Note the knight makes
Write a program that prompts the user to enter a directory and displays the number of the files in the directory.
The text presented the Sierpinski triangle fractal. In this exercise, you will write a program to display another fractal, called the Koch snowflake, named after a famous Swedish mathematician. A
Modify Listing 18.8, TowerOfHanoi.java, so the program finds the number of moves needed to move n disks from tower A to tower B. (Hint: Use a static variable and increment it every time the method is
Write a recursive method that finds the number of occurrences of a specified character in an array. You need to define the following two methods. The second one is a recursive helper method.public
Write a recursive method to return the number of uppercase letters in an array of characters. You need to define the following two methods. The second one is a recursive helper method.public static
Write a recursive method that computes the sum of the digits in an integer. Use the following method header: public static int sumDigits(long n) For example, sumDigits(234) returns 2 + 3 + 4 = 9.
Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called. (Hint: Use a static variable and increment it every time the method is called.)Data
Using the BigInteger class introduced in Section 10.9, you can find the factorial for a large number (e.g., 100!). Implement the factorial method using recursion. Write a program that prompts the
Write a program that draws two filled circles with radius 15 pixels, centered at random locations, with a line connecting the two circles. The line should not cross inside the circles, as shown in
Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field. Listing 10.6 - Course.java public class Course i private String courseNane: private string
A university posts its employees’ salaries at http:// liveexample.pearsoncmg.com/data/Salary.txt. Each line in the file consists of a faculty member’s first name, last name, rank, and salary (see
Listing 6.8 implements the hex2Dec(String hexString) method, which converts a hex string into a decimal number. Implement the hex2Dec method to throw a NumberFormatException if the string is not a
Programming Exercise 11.1 defined the Triangle class with three sides. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must adhere to this rule. Create the
A polygon is convex if it contains any line segments that connects two points of the polygon. Write a program that prompts the user to enter the number of points in a convex polygon, enter the points
Revise Listing 7.9, Calculator.java, to accept an expression as a string in which the operands and operator are separated by zero or more spaces. For example, 3+4 and 3 + 4 are acceptable
Programming Exercise 5.26 approximates e using the following series:In order to get better precision, use BigDecimal with 25 digits of precision in the computation. Write a program that displays the
Define the Triangle2D class that contains:■ Three points named p1, p2, and p3 of the type MyPoint with getter and setter methods. MyPoint is defined in Programming Exercise 10.4.■ A no-arg
Define the Circle2D class that contains:■ Two double data fields named x and y that specify the center of the circle with getter methods.■ A data field radius with a getter method.■ A no-arg
Revise the Course class as follows:■ Revise the getStudents() method to return an array whose length is the same as the number of students in the course.■ The array size is fixed in Listing 10.6.
Suppose two line segments intersect. The two endpoints for the first line segment are (x1, y1) and (x2, y2) and for the second line segment are (x3, y3) and (x4, y4). Write a program that prompts the
Rewrite Listing 3.5, ComputeTax.java, using arrays. For each filing status, there are six tax rates. Each rate is applied to a certain amount of taxable income. For example, from the taxable income
Revise Listing 3.8, Lottery.java, to generate a lottery of a two-digit number. The two digits in the number are distinct. (Hint: Generate the first digit. Use a loop to continuously generate the
Programming Exercise 2.17 gives a formula to compute the wind-chill temperature. The formula is valid for temperatures in the range between -58°F and 41°F and wind speed greater than or equal to 2.
Write a static method that draws an arrow line from a starting point to an ending point in a pane using the following method header:public static void drawArrowLine(double startX, double startY,
Write a program that draws two circles with radius 15 pixels, centered at random locations, with a line connecting the two circles. The distance between the two centers is displayed on the line, as
Write a program that prompts the user to enter the center coordinates, width, and height of two rectangles from the command line. The program displays the rectangles and a text indicating whether the
Write a program that prompts the user to enter the coordinates of five points from the command line. The first four points form a polygon, and the program displays the polygon and a text that
Modify Programming Exercise 4.6 to create five random points on a circle, form a polygon by connecting the points clockwise, and display the circle and the polygon, as shown in Figure 14.51b. L00
Write a program that displays two clocks. The hour, minute, and second values are 4, 20, 45 for the first clock, and 22, 46, 15 for the second clock, as shown in Figure 14.51c. O O Exercise14 26 12
Modify the ClockPane class in Section 14.12 to draw the clock with more details on the hours and minutes, as shown in Figure 14.52a. A O Exercise14 27 12 11 10 18:54:59 (a)
Modify the ClockPane class with three new Boolean properties—hourHandVisible, minuteHandVisible, and secondHandVisible— and their associated accessor and mutator methods. You can use the set
Write a program that displays a bean machine introduced in Programming Exercise 7.37, as shown in Figure 14.52c. Exercise14 29 (c)
Write a program that lets the user click the Refresh button to display four cards from a deck of 52 cards, as shown in Figure 15.26a. (See the hint in Programming Exercise 14.3 on how to obtain four
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.
Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The formula for the calculation is futureValue = investmentAmount * (1
Write two programs, such that one displays the mouse position when the mouse button is clicked (see Figure 15.28a), and the other displays the mouse position when the mouse button is pressed and
Write a program that draws line segments using the arrow keys. The line starts from (100, 100) in the pane and drawstoward east, north, west, or south when the right-arrow key, up-arrow key,
Write a program that displays two circles with radius 10 at location (40, 40) and (120, 150) with a line connecting the two circles, as shown in Figure 15.30b. The distance between the circles is
Write a program that displays a rectangle. You can point the mouse inside the rectangle and drag (i.e., move with mouse pressed) the rectangle wherever the mouse goes. The mouse point becomes the
Write a program that displays a circle of radius 10 pixels filled with a random color at a random location on a pane, as shown in Figure 15.31b. When you click the circle, it disappears and a new
Write a program that enables the user to drag the vertices of a triangle and displays the angles dynamically as the triangle shape changes, as shown in Figure 15.32a. The formula to compute angles is
Rewrite Programming Exercise 14.10 so the cylinder’s width and height are automatically resized when the window is resized.Data from Programming Exercise 14.10Write a program that draws a cylinder,
Twenty-five slides are stored as image files (slide0.jpg, slide1. jpg, . . . , slide24.jpg) in the image directory downloadable along with the source code in the book. The size of each image is 800 *
Modify Listing 14.21, ClockPane.java, to add the animation into this class and add two methods start() and stop() to start and stop the clock, respectively. Write a program that lets the user control
Write a program that animates the bean machine introduced in Programming Exercise 7.37. The animation terminatesafter 10 balls are dropped, as shown in Figures 15.38b and c.Data from Programming
A self-avoiding walk in a lattice is a path from one point to another that does not visit the same point twice. Self-avoiding walks have applications in physics, chemistry, and mathematics. They can
Revise the preceding exercise to display the walk step by step in an animation, as shown in Figures 15.39c and d. 100 (c) (d)
Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on. Only one light
Write a program that converts among decimal, hex, and binary numbers, as shown in Figure 16.37c. When you enter a decimal value in the decimal- value text field and press the Enter key, its
Write a program that sets the horizontal-alignment and column-size properties of a text field dynamically, as shown in Figure 16.38a. Exercise16_06 Text Field JavaFX Left • Center Right Column Size
Write a program that enables the user to specify the location and size of the circles, and displays whether the two circles intersect, as shown in Figure 16.39a. Enable the user to point the mouse
Write a program that enables the user to specify the location and size of the rectangles and displays whether the two rectangles intersect, as shown in Figure 16.39b. Enable the user to point the
Write a program that demonstrates the properties of a text area. The program uses a check box to indicate whether thetext is wrapped onto next line, as shown in Figure 16.41a. Exercise16 12 Four
Rewrite Programming Exercise 5.21 to create a GUI, as shown in Figure 16.41b. Your program should let the user enter the loan amount and loan period in the number of years from text fields, and it
Write a program that demonstrates selecting items in a list. The program uses a combo box to specify a selection mode, as shown in Figure 16.43a. When you select items, they are displayed in a label
Rewrite Programming Exercise 15.28 to add a slider to control the speed of the fan, as shown in Figure 16.43c.Data from Programming Exercise 15.28Write a program that displays a running fan, as shown
Write a program that meets the following requirements:■■ Get an audio file from the class directory using AudioClip.■■ Place three buttons labeled Play, Loop, and Stop, as shown in Figure
Write a program that displays the calendar for the current month. You can use the Prior and Next buttons to show the calendar of the previous or next month. Display the dates in the current month in
Write a GUI program for Programming Exercise 8.19, as shown in Figures 16.49a–b. Let the user enter the numbers in the text fields in a grid of 6 rows and 7 columns. The user can click the Solve
Programming Exercise 8.20 enables two players to play the connect-four game on the console. Rewrite a GUI version for the program, as shown in Figure 16.49c. The program enables two players to place
Write a program that prompts the user to enter the name of an ASCII text file and displays the frequency of the characters in the file.
Write a program that prompts the user to enter a file name, reads bytes from the file, and displays each byte’s hex representation. (Hint: You can first convert the byte value into an 8-bit string,
Write a program that prompts the user to enter a three-digit integer and determines whether it is a palindrome integer. An integer is palindrome if it reads the same from right to left and from left
Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5. For example, (2, 2) is inside the
Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure.The formula for computing
A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for
Write a program that prompts the user to enter a letter grade A, B, C, D, or F and displays its corresponding numeric value 4, 3, 2, 1, or 0. For other input, display invalid grade. Here is a sample
Write a program that prompts the user to enter 10 integers and displays all combinations of picking two numbers from the 10 numbers.
Write a method that shuffles the rows in a two-dimensional int array using the following header:public static void shuffle(int[][] m)Write a test program that shuffles the following matrix:int[][] m
A Latin square is an n-by-n array filled with n different Latin letters, each occurring exactly once in each row and once in each column. Write a program that prompts the user to enter the number n
Design a class named StopWatch. The class contains:■■ Private data fields startTime and endTime with getter methods.■■ A no-arg constructor that initializes startTime with the current
Design a class named QuadraticEquation for a quadratic equation ax2 + bx + c = 0. The class contains:■■ Private data fields a, b, and c that represent three coefficients.■■ A constructor with
Design a class named LinearEquation for a 2 × 2 system of linear equations:The class contains:■■ Private data fields a, b, c, d, e, and f.■■ A constructor with the arguments for a, b, c, d,
Design a class named MyPoint to represent a point with x- and y-coordinates. The class contains:■■ The data fields x and y that represent the coordinates with getter methods.■■ A no-arg
A bounding rectangle is the minimum rectangle that encloses a set of points in a two-dimensional plane, as shown in Figure 10.24d. Write a method that returns a bounding rectangle for a set of points
Write a program that creates an ArrayList and adds a Loan object, a Date object, a string, and a Circle object to the list, and use a loop to display all the elements in the list by invoking the
Write a program that prompts the user to enter an integer m and find the smallest integer n such that m * n is a perfect square. (Hint: Store all smallest factors of m into an array list. n is the
Write a method that returns an array list of Character from a string using the following header:public static ArrayList toCharacterArray(String s)For example, toCharacterArray("abc") returns an array
The bin packing problem is to pack the objects of various weights into containers. Assume each container can hold a maximum of 10 pounds. The program uses an algorithm that places an object into the
Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement the bin- 2Dec method to throw a NumberFormatException if the string is not a binary string.
Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown
Suppose the text file on the Web http://liveexample.pearsoncmg.com/data/Scores.txt contains an unspecified number of scores separated by spaces. Write a program that reads the scores from the file
Write a program that prompts the user to enter a file name and displays the occurrences of each letter in the file. Letters are case insensitive. Here is a sample run: Enter a filename: Lincoln.txt
Modify Listing 12.18 WebCrawler.java to search for the word(e.g., Computer Programming) starting from a URL (e.g., http://cs.armstrong .edu/liang). Your program prompts the user to enter the
Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject then implement the Triangle class. Write a test program
Write the following method that shuffles an ArrayList of numbers:public static void shuffle(ArrayList list)
Rewrite the PrintCalendar class in Listing 6.12 to display a calendar for a specified month using the Calendar and GregorianCalendar classes. Your program receives the month and year from the command
Define a class named ComparableCircle that extends Circle and implements Comparable. Draw the UML diagram and implement the compareTo method to compare the circles on the basis of area. Write a test
Redesign and implement the Rational class in Listing 13.13 using BigInteger for the numerator and denominator. Write a test program that prompts the user to enter two rational numbers and display the
A complex number is a number in the form a + bi, where a and b are real numbers and i is 2-1. The numbers a and b are known as the real part and imaginary part of the complex number, respectively.
Rewrite Programming Exercise 3.1 to obtain imaginary roots if the determinant is less than 0 using the Complex class in Programming Exercise 13.17. Here are some sample runs: Enter a, b, c: 1 3 1
The equation of a parabola can be expressed in either standard form (y = ax2 + bx + c) or vertex form (y = a(x - h)2 + k). Write a program that prompts the user to enter a, b, and c as integers in
Write a program that displays four images in a grid pane, as shown in Figure 14.43a. Exerise 14 01 (a)
Showing 200 - 300
of 348
1
2
3
4