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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 13PE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT