Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 4, Problem 18PP
Your company has shares of stock it would like to sell when their value exceeds a certain target price. Write a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write MIPS program that asks the user to enter two integers: n1 and n2 and prints the sum of all numbers from n1 to n2. For example, if the user enters n1=3 and n2=7, then the program should display the sum as 25
Write a program that repeatedly reads an integer value from the keyboard until the user enters a value that is divisible by 3 (it should not read additional values once a value divisible by three has been entered). The program should then output the sum of the values that were NOT divisible by 3.
Sample Input
10 4 12
Sample Output
14
Simplifying Assumptions
You don't need to (shouldn't) prompt the user for input.
You may assume that the user always enters valid integers.
Write a complete program that:
1. Uses a do...while loop to prompt the user to enter a count that is greater than 1 and less than or equal to 20 then reads
in a count from the keyboard as an integer.
a. If input error occurs or the count the user enters is less than or equal to 1 or greater than 20, output an error.
After outputting an error, clear/ignore the failed input and continue do...while looping until a valid number is
entered.
2. Writes a triangle to the display using for loops. The triangle will be upside down. To write this triangle to the display:
amountOfStars = number entered in (1).
a.
b. Output amountOfStars followed by a new line.
C. Decrement amountOfStars by one.
d. Continue from (b) until amountOfStars is zero.
3. Writes a triangle to the display using while loops. The triangle will be rightside up. To write this triangle to the display:
a. amountOfStars = 1.
b. Output amountOfStars followed by a new line.
C. Increment amountOfStars by one.
d. Continue from (b)…
Chapter 4 Solutions
Big Java Late Objects
Ch. 4.1 - How many years does it take for the investment to...Ch. 4.1 - If the interest rate is 10 percent per year, how...Ch. 4.1 - Modify the program so that the balance after each...Ch. 4.1 - Suppose we change the program so that the...Ch. 4.1 - What does the following loop print? int n = 1;...Ch. 4.2 - Hand-trace the following code, showing the value...Ch. 4.2 - Hand-trace the following code, showing the value...Ch. 4.2 - Hand-trace the following code, assuming that a is...Ch. 4.2 - Trace the following code. What error do you...Ch. 4.2 - Prob. 10SC
Ch. 4.3 - Write the for loop of the InvestmentTable.java...Ch. 4.3 - How many numbers does this loop print? for (int n...Ch. 4.3 - Write a for loop that prints all even numbers...Ch. 4.3 - Write a for loop that computes the sum of the...Ch. 4.3 - How would you modify the for loop of the...Ch. 4.4 - Prob. 16SCCh. 4.4 - Rewrite the input check do loop using a while loop...Ch. 4.4 - Suppose Java didnt have a do loop. Could you...Ch. 4.4 - Write a do loop that reads integers and computes...Ch. 4.4 - Write a do loop that reads integers and computes...Ch. 4.5 - What does the SentinelDemo.java program print when...Ch. 4.5 - Why does the SentinelDemo.java program have to...Ch. 4.5 - What would happen if the declaration of the salary...Ch. 4.5 - In the last example of this section, we prompt the...Ch. 4.5 - Prob. 25SCCh. 4.6 - Prob. 26SCCh. 4.6 - Google has a simple interface for converting...Ch. 4.6 - Consider a modification of the program in Self...Ch. 4.6 - Prob. 29SCCh. 4.6 - Produce a storyboard for a program that compares...Ch. 4.7 - What total is computed when no user input is...Ch. 4.7 - Prob. 32SCCh. 4.7 - What are the values of position and ch when no...Ch. 4.7 - Prob. 34SCCh. 4.7 - Prob. 35SCCh. 4.7 - Prob. 36SCCh. 4.8 - Why is there a statement System.out.println(); in...Ch. 4.8 - How would you change the program to display all...Ch. 4.8 - Prob. 39SCCh. 4.8 - What do the following nested loops display? for...Ch. 4.8 - Prob. 41SCCh. 4.9 - Prob. 42SCCh. 4.9 - You need to write a program for DNA analysis that...Ch. 4.9 - Prob. 44SCCh. 4.9 - Consider the task of finding numbers in a string....Ch. 4.10 - How do you simulate a coin toss with the...Ch. 4.10 - How do you simulate the picking of a random...Ch. 4.10 - Why does the loop body in Dice.java call...Ch. 4.10 - Prob. 49SCCh. 4.10 - Prob. 50SCCh. 4 - Given the variables String stars = ""; String...Ch. 4 - What do these loops print? a. int i = 0; int j =...Ch. 4 - What do these code snippets print? a. int result =...Ch. 4 - Write awhile loop that prints a. All squares less...Ch. 4 - Write a loop that computes a. The sum of all even...Ch. 4 - Provide trace tables for these loops. a. int i =...Ch. 4 - What do these loops print? a. for (int i = 1; i ...Ch. 4 - What is an infinite loop? On your computer, how...Ch. 4 - Write a program trace for the pseudocode in...Ch. 4 - What is an off-by-one error? Give an example from...Ch. 4 - What is a sentinel value? Give a simple rule when...Ch. 4 - Which loop statements does Java support? Give...Ch. 4 - How many iterations do the following loops carry...Ch. 4 - Write pseudocode for a program that prints a...Ch. 4 - Prob. 15RECh. 4 - Write pseudocode for a program that reads a...Ch. 4 - Write pseudocode for a program that reads a...Ch. 4 - Rewrite the following for loop into a while loop....Ch. 4 - Rewrite the following do loop into a while loop....Ch. 4 - Provide trace tables of the following loops. a....Ch. 4 - What do the following loops print? Work out the...Ch. 4 - What do the following program segments print? Find...Ch. 4 - Prob. 23RECh. 4 - Add a storyboard panel for the conversion program...Ch. 4 - In Section 4.6, we decided to show users a list of...Ch. 4 - Change the storyboards in Section 4.6 to support a...Ch. 4 - Draw a flowchart for a program that carries out...Ch. 4 - In Section 4.7.5, the code for finding the largest...Ch. 4 - What are nested loops? Give an example where a...Ch. 4 - The nested loops for (int 1 = 1; 1 = height; i++)...Ch. 4 - Suppose you design an educational game to teach...Ch. 4 - In a travel simulation, Harry will visit one of...Ch. 4 - Write programs with loops that compute a. The sum...Ch. 4 - Write programs that read a sequence of integer...Ch. 4 - Write programs that read a line of input as a...Ch. 4 - Complete the program in How To 4.1 on page 171....Ch. 4 - Write a program that reads a set of floating-point...Ch. 4 - Translate the following pseudocode for finding the...Ch. 4 - Translate the following pseudocode for randomly...Ch. 4 - Write a program that reads a word and prints each...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints the...Ch. 4 - Write a program that reads a word and prints all...Ch. 4 - Write a program that reads a string and prints the...Ch. 4 - Write a program that reads a sequence of words and...Ch. 4 - Write a program that prints all powers of 2 from...Ch. 4 - Write a program that reads a number and prints all...Ch. 4 - Prob. 18PECh. 4 - Write a program that reads an integer and...Ch. 4 - Write a program that reads an integer and...Ch. 4 - Write a program to plot the following face.Ch. 4 - Write a graphical application that displays a...Ch. 4 - Enhance Worked Example 4.1 to check that the...Ch. 4 - Mean and standard deviation. Write a program that...Ch. 4 - The Fibonacci numbers are defined by the sequence...Ch. 4 - Factoring of integers. Write a program that asks...Ch. 4 - Prime numbers. Write a program that prompts the...Ch. 4 - The game of Nim. This is a well-known game with a...Ch. 4 - The Drunkards Walk. A drunkard in a grid of...Ch. 4 - The Monty Hall Paradox. Marilyn vos Savant...Ch. 4 - A simple random generator is obtained by the...Ch. 4 - The Buffon Needle Experiment. The following...Ch. 4 - In the 17th century, the discipline of probability...Ch. 4 - Write a program that reads an initial investment...Ch. 4 - Currency conversion. Write a program that first...Ch. 4 - Write a program that first asks the user to type...Ch. 4 - Your company has shares of stock it would like to...Ch. 4 - Write an application to pre-sell a limited number...Ch. 4 - You need to control the number of people who can...Ch. 4 - Credit Card Number Check. The last digit of a...Ch. 4 - In a predator-prey simulation, you compute the...Ch. 4 - Projectile flight. Suppose a cannonball is...Ch. 4 - Radioactive decay of radioactive materials can be...Ch. 4 - The photo at left shows an electric device called...Ch. 4 - Write a graphical application that draws a spiral,...Ch. 4 - Prob. 28PPCh. 4 - Draw a picture of the four-leaved rose whose...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In Exercises 55 through 60, find the value of the given function where a and b are numeric variables of type Do...
Introduction to Programming Using Visual Basic (10th Edition)
Before GUIs became popular, the interface was the most commonly used. a. command line b. remote terminal c. sen...
Starting Out with Python (3rd Edition)
What is a storyboard?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Why are field values sometimes coded?
Modern Database Management (12th Edition)
Write a program that converts from 24-hour notation to 12-hour notation. For example, it should convert 14:25 t...
Problem Solving with C++ (9th Edition)
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
- Write a program that repeatedly reads an integer value from the keyboard until the user enters a value that is divisible by 3 (it should not read additional values once a value divisible by three has been entered). The program should then output the sum of the values that were NOT divisible by 3. Don't Prompt the user input should just use the sample input of 10,4,12arrow_forwardGiven two positive two-digit integers (10-99), the program will not accept a wrong input. An error message will be displayed until the user enters the input correctly. The program will then print "both have similar digits" if there is a digit that appears in both numbers, such as the 2 in 12 and 23. Otherwise print “no similar digit". Sample Run 1: Please enter the first number: 459 Wrong Input...Input number between 10 and 99: 89890 Wrong Input....Input number between 10 and 99: 23 Please enter the second number: 3322 Wrong Input...Input number between 10 and 99: 13 both have similar digits Sample Run 2: Please enter the first number: 459 Wrong Inpu...Input number between 10 and 99: 89 Please enter the second number: 3322 Wrong Input...Input number between 10 and 99: 2 Wrong Inpu...Input number between 10 and 99: 33 no similar digitsarrow_forwardWrite a program that reads from the user a character (‘s’ or ‘a’). ∙ If the character is ‘s’, the program reads 4 numbers from keyboard and then finds their sum. ∙ If the character is ‘a’, the program reads 4 numbers from keyboard and then finds their average. ∙ Otherwise, it prints “Wrong character” Sample Run: Sample Run1: Enter a character (s or a): s Input 4 numbers: 10.5 12 31 44 The sum of these 4 numbers is: 97.5 Sample Run2: Enter a character (s or a): a Input 4 numbers: 10 12 31 44 The average of these 4 numbers is: 24.375 Sample Run3: Enter a character (s or a): d Wrong characterarrow_forward
- Please write a program which asks the user for a number. The program then prints out the number multiplied by five. The program should function as follows: Please type in a number: 3 3 times 5 is 15 1 Sample outputarrow_forward8. Write a program to input 5 numbers from keyboard and find their sum and average. The program should allow user to continue to use the calculator with choice of Y or X to exit. Sample input: Input 5 integer numbers Integer 1: 6 Integer 2: 4 Integer 3: 6 Integer 4: 8 Integer 5: 15 The sum of 5 number is : 39 The Average is : 7.0 Do you want to continue? Press Y to continue Press X to exit Your choice [Y / X] :Y Input 5 integer numbers Integer 1: 5 Integer 2: 9 Integer 3: 15 Integer 4: 23 Integer 5: 45 The sum of 5 number is : 136 The Average is : 27.0 Do you want to continue? Press Y to continue Press X to exit Your choice [Y / X] :arrow_forwardGuessing Numbers---The problem is to guess what number a computer has in mind. You will write a program that randomly generatesan integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whetherthe input is too low or too high, so the user can make the next guess intelligently. Here is a sample run . (do it using while or do-whGuessing Numbers---The problem is to guess what number a computer has in mind. You will write a java program that randomly generates an integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whetherthe input is too low or too high, so the user can make the next guess intelligently. Here is a sample run . (do it using while or do-while)arrow_forward
- Write a program that reads from the user a character ('s' or 'a'). If the character is 's', the program reads 4 numbers from keyboard and then finds their sum. If the character is 'a the program reads 4 numbers from keyboard and then finds their average. Ötherwise, it prints "Wrong character Sample Run: Sample Runl: Enter a character (s or a) : s Input 4 numbers: 10.5 12 31 44 The sum of these 4 numbers is: 97.5 Sample Run2: Enter a character (s or a): a Input 4 numbers: 10 12 31 44 The average of these 4 numbers is: 24.375 Sample Run3: Enter a character (s or a): d Wrong characterarrow_forwardGiven two positive two-digit integers (10-99), the program will not accept a wrong input. An error message will be displayed until the user enters the input correctly. The program will then print "both have similar digits" if there is a digit that appears in both numbers, such as the 2 in 12 and 23. Otherwise print "no similar digit". Sample Run 1: Please enter the first number: 459 Wrong Input.Input number between 10 and 99: 89890 Wrong Input.Input number between 10 and 99: 23 Please enter the second number: 3322 Wrong Input.Input number between 10 and 99: 13 both have similar digits Sample Run 2: Please enter the first number: 459 Wrong Input. Input number between 10 and 99: 89 Please enter the second number: 3322 Wrong Input...Input number between 10 and 99: 2 2/3 Wrong Input.Input number between 10 and 99: 33 no similar digitsarrow_forward3. Write a program if for example, the input: 6 8 2028 prints the date June 8, 2028.arrow_forward
- Write a program using MIPS that asks the user to enter two integers: n1 and n2 and prints the sum of all numbers from n1 to n2. For example, if the user enters n1=3 and n2=7, then the program should display the sum as 25.arrow_forwardPlease write a program which asks the user for a number of days. The program then prints out the number of seconds in the amount of days given. The program should function as follows: How many days? 1 Seconds in that many days: 86400 Another example: How many days? 7 Seconds in that many days: 604800 1 2 Sample output Sample outputarrow_forwardYour relative, who goes to primary school and has just learned the multiplication table, asks you to constantly ask him. You wanted to gamify it. The computer will randomly scan in the multiplication table and the user will write the answer on the screen. There will be 10 questions in total and at the end the number of questions, the number of correct answers and the number of wrong answers will be printed on the screen. Also write a program that will print if the percentage of success is below 80, it remained and if it is above it, it passed.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY