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
- What additional variables, if any, will you need to declare?
- What input is needed for this program?
- What output will be produced by this program?
Write an Algorithm
List out the steps your program should follow to solve this problem. Remember that the order program statements are executed matters. This doesn't need to be written in Java, just a sketch of the steps that need to happen. Use the answers to the questions above as your guide.
Revisit Your Algorithm
Now that you have your algorithm, take a second to double check and ensure that you haven't missed anything and that your steps are in order. You can trace through your process as a way to double check. Here are some guiding questions:
- Did you give your variables a value before you attempted to use it?
- As you traced did you encounter steps where you didn't have enough information to complete?
Ask AI
Typically when my students would start writing programs, I would give their plans a quick double check before they started programming. But without a teacher or programming partner to give you another set of eyes on your plan, what can you do? Here's one way that using AI can be helpful. In this activity, we will use AI as a programming partner.
|
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 your algorithm. 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 developed the following algorithm to guide my programming. Identify any data or steps that might be missing from my algorithm 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? Did AI suggest any new structures that you haven't learned yet? Write your program without these suggestions. |
Step 2: Writing the Program
Open up your IDE and begin writing your program.
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.
- What should the value of
totalFuelbe once you have input three data transmissions? Explain your answer. - Run your code to determine if you are correct.
- Without using program code, explain how you would want your program to behave if fuel was found once
totalFuelwas at maximum capacity, that is, oncetotalFuel = Integer.MAX_VALUE;how should the space shuttle handle finding fuel.