Suppose a launched toy rocket's height is computed as h = vi*t - St. vi is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Suppose a launched toy rocket's height is computed as h = vi*t - St². vi is the initial velocity, and t is time in seconds since the launch (starting at 0). Write a program to read the initial velocity, then output the time and the rocket's height once per second. Stop when the height would be negative, meaning the rocket hit the ground (don't print the negative). Assume all values are integers. Ex: For input 20, the output is: 00 1 15 2 20 3 15 Hints: Use a while loop. • t squared is easily calculated as t*t. • Use this expression for the while loop: (rocketHeight >= 0). • Don't forget to increment time inside the while loop (else you'll get an infinite loop). LAB ACTIVITY 4.20.1: PRACTICE: Loops (while)** Output rocket height 1 import java.util.Scanner; 2 3 public class Main ( 4 5 6 7 8 9 10 11 12) public static void main(String[] args) { } Scanner scnr new Scanner(System.in); int rocketHeight = 0; int initialVelocity = 0; int timeSinceLaunch = 0; /* Type your code here. / Main.java 0/3 Load default template... A customer database file named CustomerDb.txt contains a list of customers (one per line), each customer consisting of a unique customer id followed by a first and last name. Given an id, output the customer's first and last name. If the id is not found, output "Not found". If the input id is 27, the output might be "Sarah Lee' (if found). FYI, the customer database's contents happen to be: 42 Mike Jones 16 Al Garcia 27 Sarah Lee 12 Stan Lee 99 Amy Hernandez Hints: • The template code has functions for opening and closing the customer database file. You need not understand those functions. Just know that fstream can be read just like System.in. You might also note that the expression evaluates to 0 when the end of file is reached, so the while loop will exit. • In the while loop, you'll want to skip the first and last names for that id, since that line's id didn't match the id to find. • After the while loop, check if the id was found (you can compare idToFind with dbid to detect this). If so, read the first and last name, and print them. Else, print "Not found". 484924341757437 LAB ACTIVITY Downloadable files CustomerDb.txt 5678 9 1 import java.util.Scanner; 2 import java.io.FileInputStream; 3 import java.io.IOException; 4 5 public class Main public static void main(String[] args) throws IOException { FileInputStream fstream= null; // file stream 10 SE234 11 4.21.1: PRACTICE: Loops** Customer lookup 12 13 14 Download Main.java String idToFind;// Using string for id in case has both numbers and Letters, Like M47 String dbId"-1"; String dbFirstName; String dbLastName; Scanner scnr = new Scanner(System.in); idToFind scnr.nextLine(); 0/4 Load default template... Suppose a launched toy rocket's height is computed as h = vi*t - St². vi is the initial velocity, and t is time in seconds since the launch (starting at 0). Write a program to read the initial velocity, then output the time and the rocket's height once per second. Stop when the height would be negative, meaning the rocket hit the ground (don't print the negative). Assume all values are integers. Ex: For input 20, the output is: 00 1 15 2 20 3 15 Hints: Use a while loop. • t squared is easily calculated as t*t. • Use this expression for the while loop: (rocketHeight >= 0). • Don't forget to increment time inside the while loop (else you'll get an infinite loop). LAB ACTIVITY 4.20.1: PRACTICE: Loops (while)** Output rocket height 1 import java.util.Scanner; 2 3 public class Main ( 4 5 6 7 8 9 10 11 12) public static void main(String[] args) { } Scanner scnr new Scanner(System.in); int rocketHeight = 0; int initialVelocity = 0; int timeSinceLaunch = 0; /* Type your code here. / Main.java 0/3 Load default template... A customer database file named CustomerDb.txt contains a list of customers (one per line), each customer consisting of a unique customer id followed by a first and last name. Given an id, output the customer's first and last name. If the id is not found, output "Not found". If the input id is 27, the output might be "Sarah Lee' (if found). FYI, the customer database's contents happen to be: 42 Mike Jones 16 Al Garcia 27 Sarah Lee 12 Stan Lee 99 Amy Hernandez Hints: • The template code has functions for opening and closing the customer database file. You need not understand those functions. Just know that fstream can be read just like System.in. You might also note that the expression evaluates to 0 when the end of file is reached, so the while loop will exit. • In the while loop, you'll want to skip the first and last names for that id, since that line's id didn't match the id to find. • After the while loop, check if the id was found (you can compare idToFind with dbid to detect this). If so, read the first and last name, and print them. Else, print "Not found". 484924341757437 LAB ACTIVITY Downloadable files CustomerDb.txt 5678 9 1 import java.util.Scanner; 2 import java.io.FileInputStream; 3 import java.io.IOException; 4 5 public class Main public static void main(String[] args) throws IOException { FileInputStream fstream= null; // file stream 10 SE234 11 4.21.1: PRACTICE: Loops** Customer lookup 12 13 14 Download Main.java String idToFind;// Using string for id in case has both numbers and Letters, Like M47 String dbId"-1"; String dbFirstName; String dbLastName; Scanner scnr = new Scanner(System.in); idToFind scnr.nextLine(); 0/4 Load default template...
Expert Answer:
Answer rating: 100% (QA)
import javautilScanner public class Main public static void mainString args Scanner s... View the full answer
Related Book For
Elementary Principles of Chemical Processes
ISBN: 978-0471720638
3rd Edition
Authors: Richard M. Felder, Ronald W. Rousseau
Posted Date:
Students also viewed these programming questions
-
A laundry detergent manufacturer wished to test a new product prior to market release. One area of concern was the relationship between the height of the detergent suds in a washing machine as a...
-
Make a Relational Model Table and Define Keys from Entity Relation Diagram Q2: Design the World Music Association Database using given ERD. ORCHESTRA "Orchestra Name City Country Music Director...
-
You are asked to develop a Floppy Disk program that allows users to access a floppy disk locally mounted on a computer. You are expected to use C programming language. In your program, all file I/O...
-
What is the effect of a viscosity (competence) difference between strain markers and the matrix?
-
Consider the volleyball net shown. Determine the angle formed by guy wires AB and AC.
-
Standard addition graph. Tooth enamel consists mainly of the mineral calcium hydroxyapatite, Ca 10 (PO 4 ) 6 (OH) 2 . Trace elements in teeth of archeological specimens provide anthropologists with...
-
Responsibilities of an object define what they know and what they do. Provide an example for each.
-
On January 1, 2018, Ithaca Corp. purchases Cortland Inc. bonds that have a face value of $150,000. The Cortland bonds have a stated interest rate of 6%. Interest is paid semiannually on June 30 and...
-
The David Derrick Insurance company wants to sells a certain policy for $1000 to John Graham Jr. They know from historic data that there is a 1 in 100 chance John will file a $20,000 claim, a 1 in...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
In the figure below BC is parallel to DE. The length of side AC is x and the length of side CE is 4x. What is the area of triangle ADE if the area of ABC is 100 cm ? D B A X 4x E
-
Calculate the expected return and standard deviation of the returns on this stock: State of Economy Boom Normal Probability of State of Economy 20% 65% 15% Rate of Return if State Occurs 16% 12% 3%...
-
BKM Industries spent $10,000 on a feasibility study to expand its production capacity. The company decided to go ahead with the expansion: It will need to buy a new machine for $50,000 and spend...
-
1. Why is it important to review existing policies before shopping for new coverage? 2. What are the advantages and disadvantages of different types of insurance intermediaries from the perspective...
-
What role do insurance companies play in the financial education of Honduran citizens? Should they take a more active role in this sense?
-
You just won a contest. The prize is a lump sum payment of $65,127, however, you will not receive this payment for 26 years. Compute the present value of your prize assuming a discount rate of 11...
-
6. Understanding Formal Report Components What should an effective letter of transmittal include? A rsum listing previous projects An announcement of the topic and affirmation of the...
-
Q:1 Take any product or service offered in Pakistan and apply all determinents of customer Perceived value ?
-
In modeling the effect of an impurity on crystal growth, the following equation was derived: where C is impurity concentration, G L is a limiting growth rate, G 0 is the growth rate of the crystal...
-
The length of the reactor is an important design parameter.What would be the drawbacks of making the reactor (i) too short, and (ii) too long?
-
Pure chlorobenzene is contained in a flask attached to an open-end mercury manometer. When the flask contents are at 58.3C, the height of the mercury in the arm of the manometer connected to the...
-
Bethany, who weighs 560 N, lies in a hammock suspended by ropes tied to two trees. One rope makes an angle of 45 with the ground; the other makes an angle of 30. Find the tension in each of the ropes.
-
In the Skycoaster amusement park ride, riders are suspended from a tower by a long cable. A second cable then lifts them until they reach the starting position indicated in Figure P5.3. The lifting...
-
A dump truck, whose bed is made of steel, holds an old steel watering trough. The bed of the truck is slowly raised until the trough begins to slide. What is the acceleration of the trough as it...
Study smarter with the SolutionInn App