java Suppose a launched toy rocket's height is computed as h = vi*t - 5t2. vi is the initial velocity, and t is time in seconds since the launch (starting at 0). Write a java 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: 0 0 1 15 2 20 3 15 4 0

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

java

Suppose a launched toy rocket's height is computed as h = vi*t - 5t2. vi is the initial velocity, and t is time in seconds since the launch (starting at 0). Write a java 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:

0 0 1 15 2 20 3 15 4 0

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 (otherwise you'll get an infinite loop).

import java.util.Scanner;

public class Main {
   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. */
   }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
个
my
Cho zy Sec zy : x zy Sec
How to Apply | Ad...
= zyBooks
Java
learn.zybooks.com/zybook/BCCPS100LuWinter2023/chapter/4/section/16
Real Boxing APK V... F Forbes Billionaires...
My library > CPS 100: Computer Programming I home >
4.16: Lab: Output rocket height
Input 20
Your output
2:Compare output
Expected output
Output differs. See highlights below. Special character legend
Suc UCL allb
Your output
Figu
Input 30
Expected output
0 0
1 15
2 20
3 15
4 0
Sup
Output differs. See highlights below. Special character legend
How to Write a CV...
0 0
1 25
2 40
3 45
4 40
5 254
Input: Output: 0 0 1 15 2 20 3 1540
Am
Mo C Sign B Brai B Sup
Curriculum Vitae (...
Curriculum Vitae (...
zyBooks catalog
Input: Output: 0 0 1 25 2 40 3 45 4 40 5 25 60
Sign
M You
Resumes and Cov...
Ans
Suc +
0/4
CV Sample for Inf...
? Help/FAQ Oluwatosin Afolaranmi
>>
Transcribed Image Text:个 my Cho zy Sec zy : x zy Sec How to Apply | Ad... = zyBooks Java learn.zybooks.com/zybook/BCCPS100LuWinter2023/chapter/4/section/16 Real Boxing APK V... F Forbes Billionaires... My library > CPS 100: Computer Programming I home > 4.16: Lab: Output rocket height Input 20 Your output 2:Compare output Expected output Output differs. See highlights below. Special character legend Suc UCL allb Your output Figu Input 30 Expected output 0 0 1 15 2 20 3 15 4 0 Sup Output differs. See highlights below. Special character legend How to Write a CV... 0 0 1 25 2 40 3 45 4 40 5 254 Input: Output: 0 0 1 15 2 20 3 1540 Am Mo C Sign B Brai B Sup Curriculum Vitae (... Curriculum Vitae (... zyBooks catalog Input: Output: 0 0 1 25 2 40 3 45 4 40 5 25 60 Sign M You Resumes and Cov... Ans Suc + 0/4 CV Sample for Inf... ? Help/FAQ Oluwatosin Afolaranmi >>
Solution
Bartleby Expert
SEE SOLUTION
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education