In Chapter 14, you created an interactive GUI version for

In Chapter 14, you created an interactive GUI version for Sammy’s Seashore Rentals. Now, rewrite the program using JavaFX and Scene Builder that allows the user to enter a rental time in hours into a text field. Also, allow the user to choose one equipment type to rent from a group of seven choices. The rental fee is $40 per hour for a personal watercraft or pontoon boat; $20 per hour for a rowboat, canoe, or kayak; and $7 per hour for a beach chair or umbrella. Let the user add an equipment lesson for an extra $5. Use a CSS file to design an interface to reflect the business. Display a message that indicates all the details for the rental, including the total price. Save the project as FXSammysSeashore.

In Chapter 14, you created an interactive GUI version of

In Chapter 14, you created an interactive GUI version of Carly’s Catering. Now, rewrite the program using JavaFX and Scene Builder. Allow the user to enter the number of guests for an event into a text field.. Also, allow the user to choose one entree from a group of at least four choices, up to two side dishes from a group of at least four choices, and one dessert from a group of at least three choices. Display the cost of the event as $35 per person; once the user has made selection changes, display a list of the current items chosen. Use a CSS file to design an interface to reflect the business. Save the project as FXCarlysCatering.

Create a simple math game for children. Use a CSS

Create a simple math game for children. Use a CSS file to make the design appealing to a young child. Allow the user to type two numbers into two text fields, and then to select the operation (addition or subtraction) to be performed on the numbers. The operation selection should be a radio button choice. The user can then type the answer into a third text field. If the answer is correct, display a congratulatory message into a label. If the answer is incorrect, ask the user to try again. Add a button to allow the user to exit the application. Name the project MathJavaFX.

Write a program that reads a connected graph from a

Write a program that reads a connected graph from a file. The graph is stored in a file using the same format specified in Programming Exercise. Your program should prompt the user to enter the name of the file then two vertices, and should display a shortest path between the two vertices. For example, for the graph in Figure, a shortest path between 0 and 1 can be displayed as 0 2 4 3 1.

Here is a sample run of the program:

Write a program that reads a connected graph from a file and displays its minimum spanning tree. The first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0, 1, …, n-1. Each subsequent line describes the edges in the form of u1, v1, w1 | u2, v2, w2 | …. Each triplet in this form describes an edge and its weight. Figure shows an example of the file for the corresponding graph. Note that we assume the graph is undirected. If the graph has an edge (u, v), it also has an edge (v, u). Only one edge is represented in the file. When you construct a graph, both edges need to be added. Your program should prompt the user to enter the name of the file, read data from the file, create an instance g of WeightedGraph, invoke g.printWeightedEdges() to display all edges, invoke getMinimumSpanningTree() to obtain an instance tree of WeightedGraph.MST, invoke tree.getTotalWeight() to display the weight of the minimum spanning tree, and invoke tree.printTree() to display the tree. Here is a sample run of the program:

(Hint: Use new WeightedGraph(list, numberOfVertices) to create a graph, where list contains a list of WeightedEdge objects. Use new WeightedEdge(u, v, w) to create an edge. Read the first line to get the number of vertices. Read each subsequent line into a string s and use s.split(“[\|]”) to extract the triplets. For each triplet, use triplet.split(“[,]”) to extract vertices and weight.)

Develop a GUI program as shown in Figure 29.2, with

Develop a GUI program as shown in Figure 29.2, with the following requirements: (1) The radius of each vertex is 20 pixels. (2) The user clicks the left mouse button to place a vertex centered at the mouse point, provided that the mouse point is not inside or too close to an existing vertex. (3) The user clicks the right mouse button inside an existing vertex to remove the vertex. (4) The user presses a mouse button inside a vertex and drags to another vertex and then releases the button to create an edge, and the distance between the two vertices is also displayed. (5) The user drags a vertex while pressing the CTRL key to move a vertex. (6) The vertices are numbers starting from 0. When a vertex is removed, the vertices are renumbered. (7) You can click the Show MST or Show All SP From the Source button to display an MST or SP tree from a starting vertex. (8) You can click the Show Shortest Path button to display the shortest path between the two specified vertices.

Modify Listing, TestWeightedGraph.java, to create a file for representing graph1.

Modify Listing, TestWeightedGraph.java, to create a file for representing graph1. The file format is described in Exercise. Create the file from the array defined in lines 7–24 in Listing. The number of vertices for the graph is 12, which will be stored in the first line of the file. An edge (u, v) is stored if u. The contents of the file should be as follows:

Listing

Write a program that reads a connected graph from a file and displays its minimum spanning tree. The first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0, 1, …, n-1. Each subsequent line describes the edges in the form of u1, v1, w1 | u2, v2, w2 | …. Each triplet in this form describes an edge and its weight. Figure shows an example of the file for the corresponding graph. Note that we assume the graph is undirected. If the graph has an edge (u, v), it also has an edge (v, u). Only one edge is represented in the file. When you construct a graph, both edges need to be added. Your program should prompt the user to enter the name of the file, read data from the file, create an instance g of WeightedGraph, invoke g.printWeightedEdges() to display all edges, invoke getMinimumSpanningTree() to obtain an instance tree of WeightedGraph.MST, invoke tree.getTotalWeight() to display the weight of the minimum spanning tree, and invoke tree.printTree() to display the tree. Here is a sample run of the program:

Write a program that enables two users to chat. Implement

Write a program that enables two users to chat. Implement one user as the server (Figure 31.21a) and the other as the client (Figure 31.21b). The server has two text areas: one for entering text and the other (noneditable) for displaying text received from the client. When the user presses the Enter key, the current line is sent to the client. The client has two text areas: one (noneditable) for displaying text from the server and the other for entering text. When the user presses the Enter key, the current line is sent to the server. Name the client Exercise31_09Client and the server Exercise31_09Server.

Programming Exercise 8.5 describes how to perform matrix addition. Suppose

Programming Exercise 8.5 describes how to perform matrix addition. Suppose you have multiple processors, so you can speed up the matrix addition. Implement the following method in parallel.

Write a test program that measures the execution time for adding two 2,000 * 2,000 matrices using the parallel method and sequential method, respectively.

Write a method to add two matrices. The header of the method is as follows:

public static double [][] addMartix(double[][] a, double[][] b)

In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each element cij is aij + bij. For example, for two 3 × 3 matrices a and b, c is

Write a test program that prompts the user to enter two 3 × 3 matrices and displays their sum. Here is a sample run:

Implement the following method using the Fork/Join Framework to assign

Implement the following method using the Fork/Join Framework to assign random values to the list.
public static void parallelAssignValues(double[] list)
Write a test program that creates a list with 9,000,000 elements and invokes parallelAssignValues to assign random values to the list. Also implement a sequential algorithm and compare the execution time of the two. Note that if you use Math.random(), your parallel code execution time will be worse than the sequential code execution time because Math.random() is synchronized and cannot be executed in parallel. To fix this problem, create a Random object for assigning random values to a small list.

Rewrite Exercise using a thread to control car racing. Compare

Rewrite Exercise using a thread to control car racing. Compare the program with Exercise by setting the delay time to 10 in both programs. Which one runs the animation faster?

Write a program that simulates car racing, as shown in Figure. The car moves from left to right. When it hits the right end, it restarts from the left and continues the same process. You can use a timer to control animation. Redraw the car with a new base coordinates (x, y), as shown in Figure. Also let the user pause/resume the animation with a button press/release and increase/decrease the car speed by pressing the UP and DOWN arrow keys.

(a) The program displays a moving car.

(b) You can redraw a car with a new base point.