Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python to complete the following: a. Open the starter code in the file: soda_can.py # A class to model soda cans # Implement a

use python to complete the following:

a. Open the starter code in the file: soda_can.py

# A class to model soda cans # Implement a class SodaCan with methods getSurfaceArea() and getVolume(). # The height and radius of a soda can object should be specified upon instantiation.  import math class SodaCan(object): def __init__(self, height, radius): self.height = height self.radius = radius self.contents = None def getHeight(self): return self.height def getRadius(self): return self.radius def setHeight(self, height): self.height = height def setRadius(self, radius): self.radius = radius def getVolume(self): V = math.pi*(r**2)*h return 0 # fix this stub   def getSurfaceArea(self): return 0 # fix this stub  if __name__ == "__main__": # b. Construct a soda can with height h = 5 inches and radius r = 2.5 inches.  # Then print out its volume V and surface area A. Use your methods getVolume and getSurfaceArea.  can = SodaCan(5, 2.5) V = can.getVolume() S = can.getSurfaceArea() print("The volume of the can is V = %0.3f" % V) print("The surface area of the can is S = %0.3f" % S) # construct a second soda can with radius 2 inches and height 8 inches.  # Which holds a greater volume?  # Use an if statement to decide.

Complete the methods shown below to return the volume and surface area of the soda can. The following formulas should be familiar.

= ^2h

= 2 ^2 + 2h

Since the math module has been imported at the top, you can use math.pi any time you need to use .

def getVolume(self): return 0 # fix this stub

def getSurfaceArea(self):

return 0 # fix this stub

b. In the main section, construct a cylindrical soda can with radius 2.5 inches and height 5 inches. Then print out its volume V and surface area A. Use your methods getVolume and getSurfaceArea.

c. Now construct a second soda can with radius 2 inches and height 8 inches. Which holds a greater volume? Use an if statement to decide.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

107 MA ammeter 56 resistor ? V voltmeter

Answered: 1 week ago

Question

Generally If Drug A is an inducer of Drug B , Drug B levels will

Answered: 1 week ago