Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 16, Problem 16.20PE
Program Plan Intro
Control a group of fans
Program Plan:
- Declare the class “stopwatch” extends “Application”.
- Method Definition for “start() ”
- Create an object for class “Time”.
- Create an object for “Text”.
- Create an object for “Timeline”.
- Call the method “increase()”.
- Set the text.
- Activate the timeline.
- Create an object for “HBox”.
- Create an object for start and clear“Button”.
- Activate the start button.
- Check whether the state of the button equals to “Start”.
- Set the text.
- Activate the “play()”.
- Check whether the state of the button equals to “Pause”.
- Set the text.
- Activate the “pause()”.
- Check whether the state of the button equals to “Resume”.
- Set the text.
- Activate the “play()”.
- Check whether the state of the button equals to “Start”.
- Activate the clear button
- Set the text.
- Activate “pause()”.
- Set the text “Start”.
- Set the font.
- Create an object for “BorderPane()”.
- Set the “h1” to “p1”.
- Create an object “sc” for scene.
- Set the stage title.
- Place the scene in the stage.
- Using the “show()” to display the stage.
- Method definition for main class.
- Call the “launch()”.
- Definition for “getSecond()” method.
- Return the calculated value.
- Definition for “getMinute()” method.
- Return the calculated value.
- Definition for “getHour()” method.
- Return the calculated value.
- Definition for “reset()” method.
- Set the “val” to “0”.
- Definition for “increase()” method.
- Increment the value of “val”.
- Definition for “toString()” method.
- Get the hour, minute and second.
- Definition for “getTwodigit()”.
- Check whether the “val” is less than “10”.
- Return the value of “val”.
- Check whether the “val” is less than “10”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q5: (Display patterns using loops) Use nested loops that display the following patterns. Your program should
prompt the user to input A, B, or C, and display the corresponding pattern. The program ends with the input -1.
(2 marks)
Pattern A
Pattern B
Pattern C
*
*******
**
*** **
k**
***
****
**** *
****
***
****
k* * **
**
*** *******
*** ***
write codes
Q3a)
Summary
Newton’s law states that the force, F, between two bodies of masses M1 and M2 is given by:
in which k is the gravitational constant and d is the distance between the bodies. The value of k is approximately 6.67 X 10-8 dyn. cm²/g² .
Instructions
Write a program that prompts the user to input:
The masses of the bodies
The distance between the bodies.
The program then outputs:
The force between the bodies.
Your program should be able to work with decimals.
Q3b)
Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service charges on the total amount for each transaction, buy or sell. When Cindy sells stocks, she would like to know if she gained or lost on a particular investment.
Instructions
Write a program that allows Cindy to input:
The purchase price of each share
The selling price of each share
The number of shares sold
The program outputs:
The total amount invested
The total amount received from selling
The total service…
Chapter 16 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 16.2 - Prob. 16.2.1CPCh. 16.2 - Prob. 16.2.2CPCh. 16.2 - Prob. 16.2.3CPCh. 16.2 - Prob. 16.2.4CPCh. 16.3 - How do you create a button with a text and a node?...Ch. 16.3 - Prob. 16.3.2CPCh. 16.3 - Prob. 16.3.3CPCh. 16.4 - What is the output of the following code? public...Ch. 16.4 - Prob. 16.4.2CPCh. 16.4 - Prob. 16.4.3CP
Ch. 16.4 - Prob. 16.4.4CPCh. 16.5 - Prob. 16.5.1CPCh. 16.5 - Can you apply all the methods for Labeled to...Ch. 16.5 - Prob. 16.5.3CPCh. 16.5 - Prob. 16.5.4CPCh. 16.6 - Prob. 16.6.1CPCh. 16.6 - Can you apply all the methods for TextInputControl...Ch. 16.6 - Prob. 16.6.3CPCh. 16.6 - Prob. 16.6.4CPCh. 16.7 - Prob. 16.7.1CPCh. 16.7 - Prob. 16.7.2CPCh. 16.7 - Prob. 16.7.3CPCh. 16.7 - Prob. 16.7.4CPCh. 16.8 - Prob. 16.8.1CPCh. 16.8 - Prob. 16.8.2CPCh. 16.8 - Prob. 16.8.3CPCh. 16.8 - Prob. 16.8.4CPCh. 16.9 - Prob. 16.9.1CPCh. 16.9 - Prob. 16.9.2CPCh. 16.9 - Prob. 16.9.3CPCh. 16.9 - How do you obtain the selected items and selected...Ch. 16.10 - Prob. 16.10.1CPCh. 16.10 - Prob. 16.10.2CPCh. 16.10 - Prob. 16.10.3CPCh. 16.11 - Prob. 16.11.1CPCh. 16.11 - Prob. 16.11.2CPCh. 16.11 - Prob. 16.11.3CPCh. 16.12 - Prob. 16.12.1CPCh. 16.12 - Prob. 16.12.2CPCh. 16.12 - How does the program check whether a player wins?...Ch. 16.13 - Prob. 16.13.1CPCh. 16.13 - Prob. 16.13.2CPCh. 16.13 - Prob. 16.13.3CPCh. 16.14 - Prob. 16.14.1CPCh. 16.14 - Prob. 16.14.2CPCh. 16 - Prob. 16.1PECh. 16 - Prob. 16.2PECh. 16 - (Traffic lights) Write a program that simulates a...Ch. 16 - (Create a miles/kilometers converter) Write a...Ch. 16 - (Convert numbers) Write a program that converts...Ch. 16 - (Demonstrate TextField properties) Write a program...Ch. 16 - Prob. 16.7PECh. 16 - (Geometry: two circles intersect?) Write a program...Ch. 16 - (Geometry: two rectangles intersect?) Write a...Ch. 16 - (Text viewer) Write a program that displays a text...Ch. 16 - (Create a histogram for occurrences of letters)...Ch. 16 - Prob. 16.12PECh. 16 - (Compare loans with various interest rates)...Ch. 16 - (Select a font) Write a program that can...Ch. 16 - (Demonstrate Label properties) Write a program to...Ch. 16 - Prob. 16.16PECh. 16 - Prob. 16.17PECh. 16 - (Simulation a running fan) Rewrite Programming...Ch. 16 - Prob. 16.19PECh. 16 - Prob. 16.20PECh. 16 - (Count-down stopwatch) Write a program that allows...Ch. 16 - (Play, loop, and stop a sound clip) Write a...Ch. 16 - (Racing cars) Write a program that simulates four...Ch. 16 - (Slide show) Programming Exercise 15.30 developed...Ch. 16 - Prob. 16.29PECh. 16 - (Pattern recognition: consecutive four equal...Ch. 16 - (Game: connect four) Programming Exercise 8.20...
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
- circles) Write a program that prompts the user to enter the center coordinates and radii of two circles and determines whether the second circle is inside the first or overlaps with the first, as shown in Figure 4.11. (Hint: circle2 is inside circle1 if the distance between the two centers <= | r1 - r2| and circle2 overlaps circle1 if the distance between the two centers <= r1 + r2.arrow_forward(Find the two highest scores)Write a program that prompts the user to enter the number of students and each student’s name and score, and displays the name and score of the student with the highest score and the student with the second-highest score.Sample RunEnter the number of students: 5Enter a student name: SmithEnter a student score: 60Enter a student name: JonesEnter a student score: 96Enter a student name: PetersonEnter a student score: 85Enter a student name: GreenlawEnter a student score: 98Enter a student name: ZhangEnter a student score: 95Top two students:Greenlaw's score is 98.0Jones's score is 96.0arrow_forwardUnlabeled Break: Create a Java program that uses a "while" loop to output the numbers from 1 to 10 to the console. Add an "if" statement inside the loop to check if the number being outputted is greater than 5. If it is, use a "break" statement to exit the loop. Labeled Break: Create a Java program that uses a labeled "for" loop to output the numbers from 1 to 5, followed by the letters A to C to the console. Add an "if" statement inside the loop to check if the number being outputted is greater than 3. If it is, use a labeled "break" statement to exit the loop completely.arrow_forward
- 6) Write a program to guess a number chosen by the user. In this program a user will choose asecret number from 1..maximum. The program will prompt the user for the maximum value,which the user will enter. The program will then make a guess as to the value of the secretnumber, and prompt the user to say if the actual number is higher, lower, or correct. Thecomputer will then guess another number until it guesses the correct secret number.arrow_forwardQ3. (Dice Rolling) Write a program that simulates the rolling of two dice. The program should use rand to roll the first die and should use rand again to roll the second die. The sum of the two values should then be calculated. [Note: Each die can show an integer value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums.] Figure 7.26 shows the 36 possible combinations of the two dice. Your program should roll the two dice 10,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Print the results in a tabular format. Also, determine if the totals are reasonable (i.e., there are six ways to roll a 7, so approximately one-sixth of all the rolls should be 7). 1 2 3 4 5 1 2 4 6 7 3 4 6 7 3 4 5 7 8 9 4 7 8 9 10 7 8 10 11 7 10 11 12 Row\Col 3.arrow_forward)java)Case1: Write a menu driven program that allows you to visit cities of oman in random order with following options. 1: Visit a city 2: Go to previous city 3: Quit the program When user presses 1: program asks user to enter the city name, and then display that the city has been visited. Please note user can visit a city any number of times When user presses 2: Program takes you back to the previous city When user presses 3: Program terminates See the below example how program interacts with the user: C:> 1: Visit a city 2: Go to previous city 3: Quit the program Enter your choice … 1 Please enter a city to visit.. Muscat You are in Muscat now… Enter your choice... 1: Visit a city 2: Go to previous city 3: Quit the program 1 Please enter a city to visit.. Ibra You are in Ibra now… Enter your choice... 1:…arrow_forward
- ((PYTHON)) Q1- Ask the user to write a number 8 times. Find the sum and the average of all those numbers then display for the user the answer of both the sum and the average. Q2- Ask the user to guess what your favorite color is. If he does not answer correctly, ask him if he wants to try again. If he does not want to try again, display for him the correct answer.arrow_forwardBasic while loop expression. Write a while loop that prints userNum divided by 4 (integer division) until reaching 2 or less. Follow each number by a space. Example output for userNum = 160:40 10 2 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.arrow_forwardQ2: Making Calculator using the switch statement. (Make two variables and then based on the operations (+ - * /) switch between them to print the result of each operation). For example if the operation was + then you should print the summation of the two numbers and so on….arrow_forward
- Q2/ Write a program that reads a code and temperature. If the code is 1, convert from centigrade to Fahrenheit. If the code is 2, convert from Fahrenheit to centigrade F = C*9/5+32 C =(F-32)*5/9arrow_forwardLab 11- JavaFX Controls Part 1: 1. Write a JavaFX program that create a simple calculator for performing addition, subtraction, multiplication, and division, as shown below. 3 Simple Calculator Fest Number: Second Number: Result: Add Subtract Multiply Divide Hints: - Use may use following structure and layout: Stage Sean Simple Calculator Border Pane Top First Number: Second Number Center Left Right Result (Grid Pane) Bottom Add Subtract Multiply Divide (Flow Pane or HBax) - The grid pane consists of three labels and three text fields, and the flow pan consists of four buttons. - The result text-field is not editable (How can you make a TextField not editable?). - How can you process the buttons' click events to perform the required basic mathematical operations? - How can you get a text from a TextField? - How can you set a text to a TextField? - How can you convert a String to a double value? How can you use Double.parseDouble() method?arrow_forwardQ5. (Find the second lowest interger number) Write a program that prompts the user to enter a set of integer numbers, and finally displays the second lowest integer number in the set. To exit from the program enter -1. Here is a sample run Enter a set of integer numbers: 3 57 928-1 The second lowest number is 3.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Literals in Java Programming; Author: Sudhakar Atchala;https://www.youtube.com/watch?v=PuEU4S4B7JQ;License: Standard YouTube License, CC-BY
Type of literals in Python | Python Tutorial -6; Author: Lovejot Bhardwaj;https://www.youtube.com/watch?v=bwer3E9hj8Q;License: Standard Youtube License