Question

PROBLEM STATEMENT The Starship Enterprise may be in difficulty! It has been ordered by Star Fleet...

PROBLEM STATEMENT

The Starship Enterprise may be in difficulty! It has been ordered by Star Fleet to go on a peaceful scientific mission around the planet Delta Tau. Unfortunately, the Deltoids are not a very nice life form. Captain James T. Kirk is worried that the planet's inhabitants may use their giant tractor beam in an attempt to pull the Enterprise down to the surface of the planet and destroy it! Naturally, the engines of the mighty Enterprise are strong enough to enable the ship to pull away from any known tractor beam. The only problem is whether or not there is enough anti-matter fuel in the engines to enable the ship to escape in time.

The amount of fuel required depends upon the altitude of the Enterprise and the strength of the tractor beam. If there is sufficient fuel, the Enterprise can escape as soon as it is attacked. If there is insufficient fuel, Captain Kirk must call down to the engine room and tell Scotty to start shoveling anti-matter into the engines.

Captain Kirk would like to know in advance what to expect if the ship is attacked. Since Commander Spock is off on vacation on a sunny beach on Planet Vulcan, it is necessary for you to write a program that will provide a minute-by-minute simulation of possible attack situations.

Write a program to do the following:

1. Interactively request and read in the initial altitude (in Km) and fuel supply (in Kg) of the Enterprise as well as the strength of the Deltoid's tractor beam (in Km/min/min). Your program must allow someone entering these data items to do so repeatedly, allowing for multiple simulations. Do this by asking the user to enter a 'y' or 'n' before each simulation, indicating whether or not a new simulation should be run at that time.

2. Compute the amount of fuel required to escape from that altitude. The amount required can be calculated using this formula:

fuel_required = (1 - altitude / 200000) * beam_strength

3. If there is sufficient fuel available, recommend escaping at once.

4. If there is insufficient fuel available, advise Captain Kirk to turn off the engines and have Scotty start shoveling. If we don't turn off the engines, Scotty might get toasted when he opens the fuel door.

5. Your program should then display a minute-by-minute status report on the Enterprise's condition. This report should continue until the Enterprise has enough fuel to escape the planet, or the ship crashes.

6. Based on the results of your report, tell the Captain how long he should wait before starting the engines, or how long before the ship will crash.

You should implement your status report in the following way:

1. Initialize the time to zero

2. Now, while the amount of fuel is less than the amount of fuel required and the current altitude is greater than zero,

a) Add one to the time
b) Compute the new current altitude using the formula:

altitude = altitude - beam_strength * time * time

c) Calculate the amount of fuel required to escape using this new altitude. Use the formula for the required fuel that was given above.

d) Compute the new amount of fuel in the engines by adding 10 Kg. to the previous amount. Scotty can shovel 10 Kg. of fuel per minute.

e) Print out the time, the current altitude, the fuel available, and the fuel required for escape.

Input/Output and Example Test Data Sets

As a minimum, test your program with the data sets shown in the example run output section below, i.e.:

 10000   100    100
 10000    75    100
 10000    25    100

Of course, you may run the program with as many data sets as you choose, and it must work for any valid data set.

Your program must ask the user for a 'y' or 'n' (and allow for 'Y' or 'N' as well) to indicate whether or not a new simulation should be run. For this input item, check for input errors and allow the user to enter a character again if they do not enter a 'y' or 'n' correctly when asked. You may assume that the user enters a single character here.

Your program does not have to check for invalid non-numeric data entries, i.e. you may assume that the user will type in only valid integer values for the three numeric data entries. However, if they type in something like a negative number for the altitude, your program must re-prompt the user until he or she enters a value which is positive. Note that positive means greater than

zero. These three values input must be read and stored as integers.

Sample Run Output

The exact format of your output is up to you, but should be at least as easy to read as the following sample run:

**********************************************************************

DELTA TAU ESCAPE SIMULATION

**********************************************************************

Enter the current altitude of the ship: 10000

Enter the current fuel supply of the ship: 100

Enter the strength of the enemy tractor beam: 100

Simulation:
*************** Computer Report on Ship Status ***********************

The Enterprise has gone into orbit around Delta Tau at an altitude of 10000 Km.
It has a fuel supply of 100 Kg. of fuel.
It has been attacked by a tractor beam of strength 100 Km/min/min.

At this altitude, 95.0 Kg. of fuel are required to escape. There is sufficient fuel to escape.

Recommendation: Start the engines and escape at once!

**********************************************************************

Do you want to run another simulation? y

Enter the current altitude of the ship: 10000 Enter the current fuel supply of the ship: 75 Enter the strength of the enemy tractor beam: 100

Simulation:
*************** Computer Report on Ship Status ***********************

The Enterprise has gone into orbit around Delta Tau at an altitude of 10000 Km.
It has a fuel supply of 75 Kg. of fuel.
It has been attacked by a tractor beam of strength 100 Km/min/min.

At this altitude, 95.0 Kg. of fuel are required to escape. There is insufficient fuel to escape.

Recommendation: Tell Scotty to start shoveling! Report of what to expect:

TIME ALTITUDE FUEL AVAILABLE FUEL REQUIRED

--------------------------------------------------------------------------------------------------

1 min 9900 KM 85 KG 95.1 KG

2 min 9500 KM 95 KG 95.2 KG

3 min 8600 KM 105 KG 95.7 KG

In 3 minutes there will be sufficient fuel to escape.
Recommend starting the engines at that time

**********************************************************************

Do you want to run another simulation? y

Enter the current altitude of the ship: 10000 Enter the current fuel supply of the ship: 25 Enter the strength of the enemy tractor beam: 100

Simulation:
*************** Computer Report on Ship Status ***********************

The Enterprise has gone into orbit around Delta Tau at an altitude of 10000 Km.
It has a fuel supply of 25 Kg. of fuel.
It has been attacked by a tractor beam of strength 100 Km/min/min.

At this altitude, 95.0 Kg. of fuel are required to escape.

There is insufficient fuel to escape.

Recommendation: Tell Scotty to start shoveling!

Report of what to expect:

TIME ALTITUDE FUEL AVAILABLE FUEL REQUIRED

--------------------------------------------------------------------------------------------

1 min   9900 KM        35 KG             95.1 KG
2 min   9500 KM        45 KG             95.2 KG
3 min   8600 KM        55 KG             95.7 KG
4 min   7000 KM        65 KG             96.5 KG
5 min   4500 KM        75 KG             97.8 KG
6 min    900 KM        85 KG             99.6 KG
7 min      0 KM        95 KG            100.0 KG

In 7 minutes the ship will crash!
Recommend sending a goodbye message to Star Fleet!

**********************************************************************

Do you want to run another simulation? n
Goodbye and Good Luck at Delta Tau!

**********************************************************************

0 0
Add a comment Improve this question Transcribed image text
Answer #1

So, here is the solution in Python3:

Here is the code that you can copy:

class Simulation:

    def __init__(self):

        self.altitude = 0

        self.fuel = 0

        self.beamS = 0

        self.fuel_required =0

        print('**********************************************************************')

        print('DELTA TAU ESCAPE SIMULATION')

        print('**********************************************************************')

    def inputData(self):

        self.altitude = 0

        self.fuel = 0

        self.beamS = 0

        self.fuel_required =0

        while(self.altitude<=0):

            self.altitude=int(input('Enter the current altitude of the ship: '))

        while(self.fuel<=0):

            self.fuel = int(input('Enter the current fuel supply of the ship: '))

        while(self.beamS<=0):

            self.beamS = int(input('Enter the strength of the enemy tractor beam: '))

    def reportData(self):

        print('*************** Computer Report on Ship Status ***********************')

        self.fuel_required = (1 - self.altitude / 200000) * self.beamS

        print('The Enterprise has gone into orbit around Delta Tau at an altitude of {} Km.'.format(self.altitude))

        print('It has a fuel supply of {} Kg. of fuel.'.format(self.fuel))

        print('It has been attacked by a tractor beam of strength {} Km/min/min.'.format(self.beamS))

        if(self.fuel_required<self.fuel):

            print('At this altitude, {} Kg. of fuel are required to escape. There is sufficient fuel to escape.'.format(self.fuel_required))

            print('Recommendation: Start the engines and escape at once!')

            

        else:

            print('At this altitude, {} Kg. of fuel are required to escape. There is insufficient fuel to escape.'.format(self.fuel_required))

            print('Recommendation: Tell Scotty to start shoveling!')

            print('Report of what to expect:')

            print('TIME\tALTITUDE\tFUEL AVAILABLE\tFUEL REQUIRED')

            print('--------------------------------------------------------------------------------------------')

            time = 0

            x=0

            while(self.fuel<self.fuel_required and self.altitude>0):

                time += 1

                self.altitude = self.altitude - self.beamS * time * time

                self.fuel_required = (1 - self.altitude / 200000) * self.beamS

                self.fuel += 10

                if(self.altitude<0):

                    self.altitude = 0

                    x=1

                print(str(time)+' min\t'+str(self.altitude)+' KM\t'+'{} KG\t'.format(self.fuel)+'{} KG'.format(self.fuel_required))

            if(x==1):

                print('In {} minutes there will be sufficient fuel to escape.'.format(time))

                print('Recommend starting the engines at that time')

            else:

                print('In {} minutes the ship will crash!'.format(time))

                print('Recommend sending a goodbye message to Star Fleet!')

        print('**********************************************************************')

    def goodbye(self):

        print('Goodbye and Good Luck at Delta Tau!')

        print('**********************************************************************')

if __name__=='__main__':

    ship = Simulation()

    consent='y'

    while(consent=='y' or consent=='Y'):

        ship.inputData()

        ship.reportData()

        consent = input('Do you want to run another simulation?')

    ship.goodbye()

If you liked the answer, do give feedback. Comment Down for more help.

2 a.py > & Simulation > inputData, 1 class simulation: def _init__(self): self.altitude = 0 self.fuel = 0 self.beams = 0 self.fuel required =0 nrint('********************************************************************** print('DELTA TAU ESCAPE SIMULATION"); r i n t ( * ** ** * ** * * * * * * * * * * * * * * * * * * * * * * * * * *** * * * * * * * * * * * * * ** * * * * * * * * def inputData(self): while(self.altitude<=0): self.altitude=int(input('Enter the current altitude of the ship: )) while(self.fuel<=0): self.fuel = int(input('Enter the current fuel supply of the ship: ") while(self.beamS<=0): self.beams = int(input('Enter the strength of the enemy tractor beam: ')) def reportData(self): print('************** ****** Computer Report on Ship Status ************************') self.fuel_required = (1 - self.altitude / 200000) * self.beams print('The Enterprise has gone into orbit around Delta Tau at an altitude of {f} km.'.format(self.altitude) print('It has a fuel supply of {f} kg. of fuel.'.format(self.fuel)) print('It has been attacked by a tractor beam of strength {} Km/min/min.'.format(self.beams) if(self.fuel required self.fuel): print('At this altitude, {f} kg. of fuel are required to escape. There is sufficient fuel to escape.'.format(self.fuel required) print('Recommendation: Start the engines and escape at once!'), else: print('At this altitude, {f} kg. of fuel are required to escape. There is insufficient fuel to escape.'. format self.fuel required) print('Recommendation: Tell scotty to start shoveling!") print('Report of what to expect:') print('TIME DALTITUDE\tFUEL AVAILABLE TFUEL REQUIRED) print('----- time = 0

X=0 while(self.fuel<self.fuel required and self.altitude>0): time += 1 self.altitude = self.altitude - self.beams * time * time self.fuel required = (1 - self.altitude / 200000) * self.beams, self.fuel += 10 if(self.altitude<o): self.altitude = 0 x=1 print(str(time)+' min\t'+str(self.altitude)+' KM\t'+'{} KG\t'.format(self. fuel)+'{} KG'.format(self.fuel required) if(x==1): print('In {f} minutes there will be sufficient fuel to escape.'.format(time) print('Recommend starting the engines at that time), else: print('In {} minutes the ship will crash!'.format(time)) print('Recommend sending a goodbye message to Star Fleet!'), nr i nt "* ** * **** * ** ** * * * * * * * * * * * * * * * * * * *** * * * * * * ** * * * * * * * * * * * * * * * * * * def goodbye(self): print('Goodbye and Good Luck at Delta Tau!'), print("**** n i nt / I* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if name__=='_main__': ship = Simulation() consent='y' while(consent=='y' or consent=='Y'); ship.inputData() ship.reportData() consent = input('Do you want to run another simulation?''), ship.goodbye() 64 65

Add a comment
Know the answer?
Add Answer to:
PROBLEM STATEMENT The Starship Enterprise may be in difficulty! It has been ordered by Star Fleet...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How do I turn this into a code I am super stuck please help!!!! ********************************************************************** DELTA...

    How do I turn this into a code I am super stuck please help!!!! ********************************************************************** DELTA TAU ESCAPE SIMULATION ********************************************************************** Enter the current altitude of the ship: 10000 Enter the current fuel supply of the ship: 100 Enter the strength of the enemy tractor beam: 100 Simulation: *************** Computer Report on Ship Status *********************** The Enterprise has gone into orbit around Delta Tau at an altitude of 10000 Km. It has a fuel supply of 100 Kg. of fuel. It...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT