Skip Top Navigation Bar

Space Mission

You are writing a program to simulate fuel consumed by a space shuttle for a space mission. The mission will include burning fuel and finding fuel. At the end of the mission, compute the average fuel per day.

Data will be received 3 separate times during your mission. Each data transmission will supply the number of days since the last transmission, the amount of fuel burned, and the amount of fuel found.

Use the following template and variable declarations for this program.

Prompt the user three separate times to obtain the number of days since last transmission, the amount of fuel used, and the amount of fuel found. Use compound operators to adjust totalFuel and missionDays based on the input values.

Compute the average fuel used per day. Compute the average two different ways. Once using integer division without casting and once using floating-point division with casting.

Step 1: Creating A Plan

Use the following questions as a guide to help you write your program.

Variables

An AI Minute, Let's Use AI!

Be sure to tell AI that you do not want it to provide you with any code at this time.

Give AI the initial prompt and provide it with the variables you have identified. Ask AI if it thinks you need any additional variables and why.

Here's a sample prompt: Do not provide any program code at this time. I have been asked to write the following program ___insert prompt_____. I've been given the variables for _____insert provided variables___ and have identified the following variables and types that I think I need. Are the data types for any of these variables incorrect or are there better types I should use and why? Are there additional variables you think I need and why? Are there any names that should be changed to be clearer and why?

Before making any updates to your plans, analyze what the AI provided by asking yourself these questions:

Do you agree with their suggestions, or is what you wrote more accurate?

Do the suggested variable name changes result in more readable code or are the variables you selected just as good?

Input and Output

Step 2: Writing the Program

Open up your IDE and begin writing your program. A good place to start your program is to break it into four stages:

The following template uses this model to help you get started. You can copy this template into a new .java file.

The // symbol creates comments that are ignored by the compiler. We will learn more about comments in a future lesson.

Step 3: Extension

Change the initial value of totalFuel to be Integer.MAX_VALUE. During each data transmission, enter a fuel found value that is larger than a fuel used value.

Predict and Compare

Trace through the new code and answer the following questions.