Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 20, Problem 20.9PE
Program Plan Intro
Program to remove the first largest ball
Program plan:
- Import the required packages into the program.
- In the Exercise20_09 class,
- In start() method,
- Create an object for buttons and HBox.
- Call addAll() method to add all buttons.
- Set the action adds or remove a ball.
- Pause and restart animation.
- Scroll bar used to control speed of animation.
- Set the maximum speed.
- Create a scene, put it into pane in stage, and display the stage.
- Define the MultipleBallPane class,
- Define the add() method to add the ball.
- Define the subtract() method to subtract the ball.
- Define the play() method to play the ball.
- Define the pause() method to pause the ball.
- Define the increaseSpeed() method to increase the speed.
- Define the decreaseSpeed() method to decrease the speed.
- Define the DoubleProperty() method to return the rate property.
- Define the moveBall() method to adjust the ball position and identify the collision.
- In start() method,
- In the Ball class extends the Circle class.
- Declare the required variables.
- Define compareTo() method to return the value.
- In the main() method,
- Launch the project.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Geometry: MyRectangle2D class) Define the MyRectangle2D class that contains:
Two double data fields named x and y that specify the center of the rectangle with getter and setter methods. (Assume the rectangle sides are parallel to the x- or y-axis.)
The data fields width and height with getter and setter methods.
A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and 1 for both width and height.
A Constructor that creates a rectangle with the specified x, y, width, and height.
A method getArea() that returns the area of the rectangle.
A method getPerimeter() that returns the perimeter of the rectangle.
A method contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle (see Figure 10.24a ).
A method contains(MyRectangle2D r) that returns true if the specified rectangle is inside this rectangle (see Figure 10.24b ).
A method overlaps(MyRectangle2D r) that returns true if the specified rectangle overlaps with this…
(Convert decimals to fractions)Write a program that prompts the user to enter a decimal number and displays the number in a fraction.Hint: read the decimal number as a string, extract the integer part and fractional part from the string, and use the Rational class in LiveExample 13.13 to obtain a rational number for the decimal number. Use the template athttps://liveexample.pearsoncmg.com/test/Exercise13_19.txt
The problem can not use BigInteger
//Below is the Rational LiveExample 13.13 that goes with the problem/question; notice "long" instead of "BigInteger"
class Rational extends Number implements Comparable<Rational> { // Data fields for numerator and denominator private long numerator = 0; private long denominator = 1;
/** Construct a rational with default properties */ public Rational() { this(0, 1); }
/** Construct a rational with specified numerator and denominator */ public Rational(long numerator, long denominator) { long gcd = gcd(numerator,…
(Intro to Java)
Explain the answers to the below questions. include a written answer to the question using step-by-step explanation
1. Write a method called arrayTimesFive
The method takes one array of doubles as a parameter
It multiplies each element in the array by 5 and stores the result
It returns nothing
Chapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
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
- (PLEASE USE JAVA AND JFRAME GUI) Game rules:The game consists of a two-dimensional field of size m × n (game field). Each element ofthe game field is a button with a number assigned to it.Initialization of the game:• The numbers on the buttons of the game field are set to a random digit between 0and 9• The target value is displayed above the game field• The current sum of the numbers displayed on the buttons of the game field is printedbelow the game field• The number of moves to completion is displayed in the upper right corner above thegame field.Playing:The first move is determined by the player by selecting any button (button A) on thegame field.1. The player is allowed to choose a second button (button B) located in the columnor row of the previously selected button (A).2. Upon selecting the second button (B), the value of button (A) is updated accordingto the following formula: A = (AoperationB)mod10.3. The operation for the basic game will be +.4. Decrement the number of moves…arrow_forward(Written in Java or Python) Write a program that allows a user to select 3 points on a graphics panel. Then, draw a triangle using these 3 points. Allow the user to specify a number of random points to be generated inside of the triangle. For each random point that is within the boundaries of the triangle draw a small dot at each of the points that are halfway between the randomly generated point and each vertex of the triangle. Do not draw the randomly generated point. Allow the user to repeat the process without removing the old dots. Allow the user to clear the screen.arrow_forward(True/False): When a program’s source code is modified, it must be assembled and linkedagain before it can be executed with the changesarrow_forward
- (True/False): A segment description includes a segment's base location.arrow_forward(CLO3) Read the following description and answer the following questions about it: Problem Description: A car dealership allows customer to purchase their new cars with different options. At this time, those options are color, model, and air condition, as shown below in class CustomerOrder. Of course, the dealership wants the software to be flexible enough to be able to add more options in the future, if needed. CustomerOrder -carColor: String -carModel: String -hasAirCondition: boolean Q1) Write the full required code in Java to use the Builder design pattern to create class CustomerOrder. Q2) Write a Java main() method to create an object of class CustomerOrder with color "red" and without air condition.arrow_forward(Java) Open up Eclipse and create a new class called ArrayListPractice.java Next, copy and paste the below program into your file and run the code. Your job is to take the given code, remove all the arrays and replace them with the identical ArrayLists. There should be no arrays in your program. You will need to call the ArrayList methods as defined in the lesson notes above. Note that you will not be able to do method overloading with ArrayLists so you should assign different names to your methods. Once you have made the changes, you should get identical output as the given version of the program. Submit your program when you are finished. /** * @author * CIS 36B * Activity 5.2 */import java.util.ArrayList;import java.util.Scanner;public class ArrayListPractice { public static void main(String[] args) { int scores[] = {95, 96, 97, 98, 99}; System.out.println("Integer exam scores:"); print(scores); System.out.println();…arrow_forward
- (Java) Open up Eclipse and create a new class called ArrayListPractice.java Next, copy and paste the below program into your file and run the code. Your job is to take the given code, remove all the arrays and replace them with the identical ArrayLists. There should be no arrays in your program. You will need to call the ArrayList methods as defined in the lesson notes above. Note that you will not be able to do method overloading with ArrayLists so you should assign different names to your methods. Once you have made the changes, you should get identical output as the given version of the program. Submit your program when you are finished. /** * @author * CIS 36B * Activity 5.2 */ import java.util.ArrayList; import java.util.Scanner; public class ArrayListPractice { public static void main(String[] args) { int scores[] = {95, 96, 97, 98, 99}; System.out.println("Integer test scores:"); print(scores); System.out.println();…arrow_forward(Intro to Java) Open a new Java file called ArrayMethods.java. Read the Javadoc comment for each method below and write the method according to the description in the comment Once you are getting the correct output for all tests inside of main, upload your source file to Canvas public class ArrayMethods { /** * Displays the contents of an array on the console * with each element separated by a blank space * Prints a new line character last * @param nums the array to print to the console */ public static void printArray(int[] nums) { return; } /** * Assuming an array of integers, return true if 1 * is the first element or 1 is the last element * Note: you may assume that you will be given an array * of at least length 1 * is1FirstLast([1, 2, 10]) → true * is1FirstLast([10, 1, 2, 1]) → true * is1FirstLast([13, 10, 1, 2, 3]) → false * @param numbers the array of int numbers * @return whether or not 1 is the first or…arrow_forward(True/False): An Object file is produced by the Linkerarrow_forward
- (Convert decimals to fractions) Write a program that prompts the user to enter a decimal number and displays the number in a fraction. Hint: read the decimal number as a string, extract the integer part and fractional part from the string, and use the Rational class to obtain a rational number for the decimal number. Sample Run 1Enter a decimal number: 3.25 The fraction number is 13/4 Sample Run 2Enter a decimal number: -0.45452 The fraction number is -11363/25000arrow_forward(YOU ARE NOT ALLOWED TO USE ARRAYLIST IN THIS PROJECT)Write a Java program to simulate a blackjack game of cards. The computer will play the role of the dealer. The program will randomly generate the cards dealt to the player and dealer during the game. Cards in this game will be represented by numbers 1 to 13 with Ace being represented by a 1. Remember, that face cards (i.e. Jack, Queen, and King) are worth 10 points to a hand while an Ace can be worth 1 or 11 points depending on the user’s choice. The numbered cards are worth their number value to the hand.arrow_forward(code on expo)Code an add screen that will allow the user to input information about a book, such as the title,author,genre and number of pages. You can can use the TextInput component to create text fields for each piece of information and a button to submit the information and add it to the library.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning