Write a Java applicationthat prompts for the distance to be traveled in kilomete
ID: 3545333 • Letter: W
Question
Write a Java applicationthat prompts for the distance to be traveled in kilometers (you will need to convert this to meters). Then, determine the number of burns required to reach the destination within 35 meters. Output the burn number, how far the probe traveled for the burn, and the remaining distance to reach its destination. You must use a While loop in your script.Things to Note: 1. The Burn and distance traveled and the Write a Java applicationthat prompts for the distance to be traveled in kilometers (you will need to convert this to meters). Then, determine the number of burns required to reach the destination within 35 meters. Output the burn number, how far the probe traveled for the burn, and the remaining distance to reach its destination. You must use a While loop in your script.
Things to Note: 1. The Burn and distance traveled and the Things to Note: 1. The Burn and distance traveled and the
Explanation / Answer
import java.util.Scanner; public class Burn { public static void main(String[] args) { final double ARRIVAL = (0.05 * 1000), BURN_FACTOR = 0.6; double initialDistance, distanceLeft, distance; int burn = 1; Scanner scanner = new Scanner(System.in); System.out.print("Enter the distance to be traveled in km : "); initialDistance = scanner.nextDouble(); distanceLeft = initialDistance * 1000; while (distanceLeft >= ARRIVAL) { distance = (initialDistance * 1000) * BURN_FACTOR; distanceLeft = (initialDistance * 1000) - distance; System.out.println("Burn " + burn + ": Traveled " + distance); System.out.println(distanceLeft + "m to go!"); burn++; } scanner.close(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.