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
introduction to java programming and data structure
Introduction To Java Programming And Data Structures Comprehensive Version 12th Edition Y. Daniel Liang - Solutions
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 illegal. Write a program to check whether a Java source-code file has correct pairs of grouping
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 y-coordinates and then in increasing order of their x-coordinates. Display the x- and y-coordinates of
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 GenericMatrix class and implement the add, multiple, and zero methods. You need to modify
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 find the max, and displays the maximum number.
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 that prompts the user to enter five strings and displays them in reverse order.
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 only L-shaped moves (two spaces in one direction and one space in a perpendicular direction). As shown
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 Koch snowflake is created as follows:1. Begin with an equilateral triangle, which is considered to be
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 called.)Data from Listing 18.8, 1 import java.util.Scanner; 2 3 public class Tower0fHanoi { 4 1**
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 static int count(char[] chars, char ch)public static int count(char[] chars, char ch, int high)Write a
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 int count(char[] chars)public static int count(char[] chars, int high)Write a test program that
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. Write a test program that prompts the user to enter an integer and displays its sum.
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 from Listing 18.2, 1 1mport java.util.Scanner; 2 3 publ1c class ComputeFibonacci { 1** Main method
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 user to enter an integer and displays its factorial.
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 Figure 14.49c. O O Exercise14 22 (c)
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 ) students new string(1001; private int numberofstudents: public Course (String courselame)
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 Programming Exercise 12.24). Write a program to display the total salary for assistant professors,
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 hex string. Write a test program that prompts the user to enter a hex number as a string and displays
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 IllegalTriangleException class, and modify the constructor of the Triangle class to throw an
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 clockwise, then displays the area of the polygon. For the formula for computing the area of a
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 expressions. Here is a sample run: Command Prompt :\exercise>java Exercise10_26 "3+4" 3 + 4 = 7 3+4
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 e value for i = 100, 200, . . . , and 1000. 1 e = 1 + 1! 1 1 1 2! 3! 4! i!
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 constructor that creates a default triangle with the points (0, 0), (1, 1), and (2, 5).■ A constructor
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 constructor that creates a default circle with (0, 0) for (x, y) and 1 for radius.■ A constructor
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. Revise the addStudent method to automatically increase the array size if there is no room to add
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 user to enter these four endpoints and displays the intersecting point. As discussed in Programming
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 of $400,000 for a single filer, $8,350 is taxed at 10%, (33,950 - 8,350) at 15%, (82,250 - 33,950) at
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 second digit until it is different from the first digit.)
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 program that prompts the user to enter a temperature and a wind speed. The program displays
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, double endX, double endY, Pane pane) Write a test program that randomly draws an arrow line, as shown in
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 shown in Figure 14.49b. A00 Exercise14.21 197,7710829908327 (b)
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 two are overlapping, whether one is contained in the other, or whether they don’t overlap, as
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 indicates whether the fifth point is inside the polygon, as shown in Figure 14.51a. (Hint: Use the Node’s
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 Exercise14 25 (b)
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 12 3 9 3) 6. (c)
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 methods to make a hand visible or invisible. Write a test program that displays only the hour and minute
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 random cards.) e 00 Exercise15 01 Refresh (a)
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. Check the boundary to prevent the ball from moving out of sight completely. O O Exercise15_03 Left
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 + monthlyInterestRate)years*12 Use text fields for the investment amount, number of years, and
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 ceases to display it when the mouse button is released. O Exercise15_08 (75.0, 70.0) (a)
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, left-arrow key, or down-arrow key is pressed, as shown in Figure 15.28b. O O Exercise15 09 (b)
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 displayed along the line. The user can drag a circle. When that happens, the circle and its line are
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 center of the rectangle.
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 random-color circle is displayed at another random location. After 20 circles are clicked, display the
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 given in Listing 4.1. e 00 Exercise15 20 78.69 51.34 49.97 (a)
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, as shown in Figure 14.45c. You can use the following method to set the dashed stroke for an
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 * 600. Write a program that automatically displays the slides repeatedly. Each slide is shown for two
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 the clock with the Start and Stop buttons, as shown in Figure 15.38a. e00 Exercisel5 32 12 Stop
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 Exercise 7.37. The bean machine, also known as a quincunx or the Galtonbox, is a device for
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 be used to model chain-like entities such as solvents and polymers. Write a program that displays a
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 can be on at a time (see Figure 16.37a). No light is on when the program starts. e00 xercise16_03 Red
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 corresponding hex and binary numbers are displayed in the other two text fields. Likewise, you can enter
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 12 (a)
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 inside a circle and drag it. As the circle is being dragged, the circle’s center coordinates in the
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 mouse inside a rectangle and drag it. As the rectangle is being dragged, the rectangle’s center
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 score and seven years ago our fath continent, a new nation, concelved in il proposition that all men are
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 should display the monthly and total payments for each interest rate starting from 5% to 8%, with
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 below the list. Exercsels, 16 Choone Selectios Mode: MLTIE Chna pan Kora india Malayvia atertel iem
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 in Figure 15.35c. Use the Pause, Resume, and Reverse buttons to pause, resume, and reverse fan
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 16.46a.■■ If you click the Play button, the audio file is played once. If you click the Loop
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 black and display the dates in the previous month and next month in gray, as shown in Figure 16.48.
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 button to highlight a sequence of four equal numbers, if it exists. Initially, the values in the text
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 red and yellow discs in turn. To place a disk, the player needs to click an available cell. An
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, then convert the bit string into a two-digit hex 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 to right. A negative integer is treated the same as a positive integer. Here are sample runs of this
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 rectangle and (6, 4) is outside the rectangle, as shown in Figure 3.7b.Enter a point with two
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 the area of a pentagon iswhere s is the length of a side. The side can be computed using the formula
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 computing the area of a regular polygon isHere, s is the length of a side. Write a program that prompts the
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 run:Enter a letter grade: BThe numeric value for grade B is 3Enter a letter grade: TT is an invalid
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 = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}};
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 and the array of characters, as shown in the sample output, and checks if the input array is a Latin
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 time.■■ A method named start() that resets the startTime to the current time.■■ A method named
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 the arguments for a, b, and c.■■ Three getter methods for a, b, and c.■■ A method named
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, e, and f.■■ Six getter methods for a, b, c, d, e, and f.■■ A method named isSolvable() that
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 constructor that creates a point (0, 0).■■ A constructor that constructs a point with specified
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 in a two-dimensional plane, as follows:public static MyRectangle2D getRectangle(double[][]
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 object’s toString() method.
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 product of the factors that appear an odd number of times in the array list. For example, consider m =
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 list that contains characters 'a', 'b', and 'c'.
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 first bin in which it would fit. Your program should prompt the user to enter the total number of
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 test program that prompts the user to enter a binary number as a string and displays its
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 in Figure 12.13. Command Prompt O X c:\exercise>java Exercise12_13 Welcome.java File Welcome.java
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 and displays their total and average.
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 JEnter Number of As: 56 Number of Bs: 134 Number of Zs: 9
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 word and the starting URL and terminates once the word is found. Display the URL for the page that
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 that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate
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 line. For example:java Exercise13_04 5 2016This displays the calendar shown in Figure 13.9.The
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 class to find the larger of two instances of ComparableCircle objects, and the larger between a
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 results as shown in the following sample run: Enter the first rational number: 3 454 Enter Enter
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. You can perform addition, subtraction, multiplication, and division for complex numbers using the
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 Enter The roots are -0.381966 and -2.61803
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 standard form and displaysin the vertex form. Display h and k as rational numbers. Here are some
Write a program that displays four images in a grid pane, as shown in Figure 14.43a. Exerise 14 01 (a)
Write a program that displays a tic-tac-toe board, as shown in Figure 14.43b. A cell may be X, O, or empty. What to display at each cell is randomly decided. The X and O are the image files x.gif and o.gif. e 0e Exercise14 02 (b)
Showing 200 - 300
of 346
1
2
3
4
Step by Step Answers