12.8. Studio: Objects & Math¶
In the exercises, you created objects to store data about the candidates for our animal astronaut corps. For this studio, we provide you with a ready-made set of candidates.
You must create code to:
Select the crew.
Perform critical mission calculations.
Determine the fuel required for launch.
12.8.1. Select the Crew¶
To access the code for exercise 1, open this repl.it link.
188.8.131.52. Randomly Select ID Numbers¶
Each candidate was assigned an ID number, which is stored in the candidate's
data file and in the
selectRandomEntryfunction to select a random entry from the
idNumbersarray. Review the Combining Math Methods section if you need a reminder on how to do this.
Call the function three times to select three ID numbers. Store these selections in a new array, making sure to avoid repeated numbers. No animal can be selected more than once!
arrayName.includes(item) can be used to check if the array already contains
while loop can keep the selection process going until the
desired number of entries have been added to the array.
184.108.40.206. Build a
Design a function that takes two arrays as parameters. These hold the randomly selected ID numbers and the candidate objects.
Use one or more loops to check which animals hold the lucky ID numbers. They
will be going on the space mission! Store these animals in a
and then return that array.
Use a template literal to print,
'____, ____, and ____ are going to space!'
Fill in the blanks with the names of the selected animals.
12.8.2. Orbit Calculations¶
To access the code for the orbit calculations and first bonus mission, go to repl.it.
Spacecraft orbits are not circular, but we will assume that our mission is special. The animals will achieve a circular orbit with an altitude of 2000 km.
Define a function that returns the circumference (C = 2πr) of the orbit. Round the circumference to an integer.
missionDurationfunction to take three parameters - the number of orbits completed, the orbit radius, and the orbital speed. Set the default radius to 2000 km and the default orbital speed to 28000 km/hr.
Calculate how long it will take our animals to complete a certain number of orbits (
time = distance/speed). Round the answer to 2 decimal places, then return the result.
For example, with the default radius and speed, 5 orbits will take about
'The mission will travel ____ km around the planet, and it will take ____ hours to complete.'
Time for an excursion! Code an
oxygenExpendedfunction to accomplish the following:
The function should take a candidate object as a parameter and NOT the
When you call
oxygenExpended, feel free to use your
selectRandomEntryto pick the crew member to pass into the function.
The spacewalk will last for three orbits around the earth. Use
missionDurationto calculate how many hours the spacewalk will take.
Use the candidate's
o2Usedmethod to calculate how much oxygen (O 2) they consume during the spacewalk. Round the answer to 3 decimal places.
Return the string,
'__ will perform the spacewalk, which will last __ hours and require __ kg of oxygen.'Fill in the blanks with the animal's name, the spacewalk time, and the amount of O 2 used.
We should not restrict our mission to the default values for orbital radius and orbital speed. Refactor
oxygenExpendedto accept values for these items. Remember to include the values in the
12.8.3. Bonus Missions¶
220.127.116.11. Conserve O 2¶
Instead of randomly selecting a crew member for the spacewalk, have your program select the animal with the smallest oxygen consumption.
18.104.22.168. Fuel Required for Launch¶
To access the code for this bonus mission, go to repl.it.
A general rule of thumb states that it takes about 9 - 10 kg of rocket fuel to lift 1 kg of mass into low-earth orbit (LEO). For our mission, we will assume a value of 9.5 kg to calculate how much fuel we need to launch our crew into space.
crewMassfunction that returns the total mass of the selected crew members rounded to 1 decimal place.
The mass of the un-crewed rocket plus the food and other supplies is 75,000 kg. Create a
fuelRequiredfunction to combine the rocket and crew masses, then calculate and return the amount of fuel needed to reach LEO.
Our launch requires a safety margin for the fuel level, especially if the crew members are cute and fuzzy. Add an extra 200 kg of fuel for each dog or cat on board, but only an extra 100 kg for the other species. Update
fuelRequiredto account for this, then round the final amount of fuel UP to the nearest integer.
'The mission has a launch mass of ____ kg and requires ____ kg of fuel.'Fill in the blanks with the calculated amounts.