Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 4, Problem 12PP
Program Plan Intro
Bouncing Ball JavaFX
Program plan:
- Include necessary header files.
- Declare the class “BounceJavaFX” that extends application class.
- Declare required constant variables.
- Define the “main()” function.
- Launch the application.
- Override the “start ()” method.
- Create a group, scene, canvas and graphics context.
- Declare required variables and update them with values.
- Do till the value of “bounce” reaches 5 using “while” condition.
- Update the value of “height”.
- Update the value of “velocity”.
- Update the value of “time”.
- Check if the value of “height” is less than 0.
- Update the value of “height”.
- Update the value of “velocity”.
- Increment the value of “bounce” by 1.
- Print “Bounce!”
- Print the time and height.
- Print the value of x and y positions.
- Update the value of “ball_Y”.
- Draw a circle and update the value of “ball_X”.
- Add the canvas.
- Set the title.
- Add the scene to the stage and display it.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You are to write a program that allows the user to draw a simple house using 5 mouse clicks.
- The first two clicks will be the opposite corners of the rectangular frame of the house.
- The third click will indicate the center of the top edge of the rectangular door. The door should have a total width that is 1/5 of the width of the house frame. The sides of the door should extend from the corners of the top down to the bottom of the frame.
- The 4th click will indicate the center of a square window. The window is as wide as the door. (A change from the original book program.)
- The last click will indicate the peak of the roof. The edges of the roof will extend from the point at the peak to the corners of the top edge of the house frame. Make the lines of the roof edge green. (Another change from the original book program.)
You are working as a software developer on NASA's Mars Explorer robotic rover project. You need to implement some code to compute the
surface area of the 3D, tube-shaped part shown below: a cylinder of radius r and height h (in units centimeters) with a hollowed-out center also
in the shape of a cylinder with radius n and height h (also in cm). Both the outside and the inside of the tube will need to be coated in a thin
layer of gold, which is why we need to know its surface area. Write code that will compute and print the total surface area of the shape.
n
esc
r
Examples:
Inputs
r = 10, n = 8.5, h = 22.5
r = 9.25, n = 6.8, h
r = 4.15, n = 3.9, h = 11.7
= 12.16
X
h
Output Value
2789.7342763877364
1473.347264273195
604.4267185874082
2
3
80
F3
000
DO
F4
✓0
F5
完成时间:18:42
PNEUE
MacBook Air
F6
F7
DII
F8
tv
8
F9
F10
F
java 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 the Figure.
(Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to 10 / 2 and its vertical distance to (0, 0) is less than or equal to 5 / 2.)
Here are sample runs of the program:
Sample 1:
Enter a point with two coordinates: 2 2
Point (2.0, 2.0) is in the rectangle
Sample 2:
Enter a point with two coordinates: 6 4
Point (6.0, 4.0) is not in the rectangle
Analysis:
(Describe the problem including input and output in your own words.)
Design:
(Describe the major steps for solving the problem.)
Coding: (Go over your code step by step)
Testing: (Describe how you test this program). In other words run your code with sample outputs.
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Can the body of a while loop execute zero times?...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Revise the following code so that it uses a while...Ch. 4.1 - What output is produced by the following code? int...Ch. 4.1 - Imagine a program that reads the population of a...Ch. 4.1 - Prob. 7STQCh. 4.1 - What output is produced by the following code? int...Ch. 4.1 - What output is produced by the following code? for...Ch. 4.1 - What output is produced by the following code? for...
Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - (Challenge) Repeat the previous project, but...Ch. 4 - Write a JavaFx application that displays a series...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- THIS NEEDS TO BE DONE IN C#!! The Tourtise and The Hair In this lab, we will be simulating the classic race of the tourtise and the hare. The race will take place on two paths of 70 tiles, which spans from left to right. The path will have two lanes, one for each animal. The path will be represented as an array of 70 characters, where each character will be the following: · A dash(i.e, “-“), which represents an empty tile. · An “h”, which represents the hare on the hare lane. · A “t”, which represents the tourtise on the tortise lane. All tiles will be “empty” (i.e. set to the dash) with the exception of the tiles that are occupied by the animals. As the animals move, the previous tile the animal was on will be set to empty, and the new tile will be changed to either “h” or “t”. Tile 70 will be the finishing tile, and the first animal to that tile will be declared the winner of the race. We will use randomization to determine how far each animal will move. Since this race will be…arrow_forwardCalculating the area under a curve is a standard problem in numerical methods. What you will develop is an app that calculates and displays the area under a range of curves. Figure 1: Area under the curve of y = x2 over the range 1 to 2, with 1 trapezoid. The area can be calculated by drawing one or more polygons (trapezoids) that approximate the curve. We start by drawing a trapezoid that encompasses our curve between the given limits and the x-axis, so for equation 1 of table 1, it looks like figure 1. We then calculate the area of the trapezoid. Notice that the trapezoid over-estimates the true area. With enough (smaller) trapezoids we can get a very good approximation to the area under the curve (see figure 2). The sum of the area of the smaller trapezoids is the area under the curve. The area of a trapezoid is given by: A = ½ (h1 + h2) d Plot graphs of the equations in table 1 for varying (input) total numbers of trapezoids. Compute and display the area between each curve and…arrow_forwardWrite code for Java fx programmingarrow_forward
- Using Java, solve the following problem using JavaFX: Write a program (Call the class ImageDisplay) that displays four images in a grid pane, as shown below. You are given 4 flags for the display, but you are free to choose other images. You are to use a GridPane for the layout. Also use ImageView. You will need to create an object for each image and use add method of GridPane to add an image to a specified row and column layout.arrow_forwardYou wrote a program to draw a line from (24, 154) to some point (a, b). Your program draws the line using 75 pixels. While drawing, NE and E points were chosen equal number of times [assume that (24, 154) is neither an NE nor an E point]. What is the value of b? (Hint: a = 98).arrow_forwardWrite a python program that draws graphing paper as in the example shown. Graphing paper must have 50 pixels margin around. Squares dimension is 20 pixels by 20 pixels. Use at least 3 functions. Do not use libraries. The graph must be drawn in GUI window and include click to exit. Graphing paper must have the red and blue axis with the arrow in the middle, and be able to adapt to the screen size. Thanks.arrow_forward
- Write a JavaFX program to design a graphical user Interface for Women's Salon Reservation System. The Main Window Should have 5 Buttons Along with the LOGO named Beauty salon placed at the top of the window. The 5 buttons are: 1- Add booking 2- Update booking 3- Delete booking 4- Search booking 5- Services (You can write some services like: hair dry, nails care, skin care ....etc ). Here is some detailes about the buttons: Add Booking: The system will ask the user to enter the user information (Name, Phone number, Date Booked, service or anything related to your project. Once the Booking is added a message Booking confirmed with name and service, Date Booked will be displayed. * The System need to check if the same Phone number is available, then you can add service to the same user.* The System should check the availability of the time. Update Booking: Can update the booking date or service, etc.. for the user. Phone number is the primary key to check for user information. Delete…arrow_forwardIN PYTHON ONLY: Write a program that uses radio buttons to select background colors for text, as shown in Figure 9.34. The available colors are red, yellow, white, gray, and green. The program uses the buttons <= and => to move the text left or right. The <= and => buttons move the message on the panel, and you can also set the background color for the message.arrow_forwardPYTHON Consider the code below. The program does a very simple animation. Change the program so that a GREEN CIRCLE travels down the center of the screen and a BLUE CIRCLE travels from the lower left corner to the top right corner.arrow_forward
- A simple plant -see the figure- can be constructed using simple Java instructions. a. Write a java code to construct the above shape. b. A list of such plant on the same line can be easily constructed using suitable Java geometric transformations -see the figure- develop a java code to make such line of plants. c. Many successive lines can also be constructed to create a field of plants, develop a java code to implement the plants field. d. Using suitable rendering, you can assign different random colors -of course all of the colors are of green grades- to each plant, develop a java code to implement such coloring. e. Using suitable randomization, rotate each plant in d) to mimic the situation that some plants are not totally vertical. f. Using suitable randomization, write a java code to assign a different size to each plant. g. If we want to change the direction of the full scene in f) with an arbitrary angle, write a java code to do that. h. Snapshot the output in g)arrow_forwardImage binarization converts a greyscale or a coloured image to a black and white image. Assume that you are given a greyscale image with text as shown in Figure 2 below. Write the Java program to convert the greyscale image to a black and white image. You may set your own estimated threshold value. A VILLAGE OF MORMONS-Over seven hun- dred Mormons reached this city from New York May 15th, and tarried with us till the early train westward set off this morning. There were enough of them to constitute a good sized village. Figure 2: Greyscale Text Imagearrow_forwardImplement an application that will compute and display the INTEGRAL image feed along with the stereo and RGB feed. You cannot use a built-in function such as “output = integral_image(input)”arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT