Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1.What will the following code print? waterGlass.py waterMain.py import waterGlass class WaterGlass: def main(): Ben = waterGlass.WaterGlass(12) Tim = waterGlass.WaterGlass(16) Mike = waterGlass.WaterGlass(10) print(Ben's

1.What will the following code print?waterGlass.pyclass Water Glass:waterMain.pyimport water Glassdef __init__(self, vol2. Write the following methodssimplify() -> which receives no additional parameters. It makes sure that the numerator and de

1.What will the following code print? waterGlass.py waterMain.py import waterGlass class WaterGlass: def main(): Ben = waterGlass.WaterGlass(12) Tim = waterGlass.WaterGlass(16) Mike = waterGlass.WaterGlass(10) print("Ben's cup has",Ben.getWaterLevel(),'oz') print("Tim's cup has",Tim.getWaterLevel(),'oz') print("Mike's cup has",Mike.getWaterLevel(),'oz') def _init_(self, volume): self.mVolume = volume self.mWaterLevel = volume return # ACCESSOR methods def getVolume(self): return self.mVolume Ben.drinkWater(5) Mike.drinkWater(5) Tim.spill() print("Ben's cup has",Ben.getWaterLevel(),'oz') print("Tim's cup has",Tim.getWaterLevel(),'oz') print("Mike's cup has",Mike.getWaterLevel(),'oz') Ben.drinkWater(5) Mike.drinkWater(5) Tim.drinkWater(3) print("Ben's cup has",Ben.getWaterLevel(),'oz') print("Tim's cup has",Tim.getWaterLevel(),'oz') print("Mike's cup has",Mike.getWaterlevel(),'oz') def getWaterLevel(self): return self.mWaterLevel # SPECIALTY methods def fillUp(self): self.mWaterLevel = self.mVolume return def drinkWater(self, amount): if amount > self.mWaterLevel: self.mWaterLevel = 0 Ben.drinkWater(5) Mike.drinkWater(5) Tim.fillUp() print("Ben's cup has",Ben.getWaterLevel(),'oz') print("Tim's cup has",Tim.getWaterLevel(),'oz') print("Mike's cup has",Mike.getWaterLevel(),'oz') else: self.mWaterLevel = self.mWaterLevel - amount return def spill(self): self.mWaterLevel = 0 return return main() ANSWER HERE: 2. Write the following methods simplify() -> which receives no additional parameters. It makes sure that the numerator and denominator are simplified to the lowest fraction. plus() does not modify self or other -> which receives one additional parameter (other). It adds the two fractions together and returns a fraction. It plusequals() -> which receives one additional parameter (other). It adds the two fractions together puts the answer in self. Remember to make sure that the signs are correct, and the fraction has been simplified.

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

Ans 1 code Here i have commented the code to explain the steps waterGlasspy class WaterGlass Initialized the value in the constructor of the class WaterGlass def initself volume selfmVolume volume sel... 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

Microsoft Visual C# An Introduction to Object-Oriented Programming

Authors: Joyce Farrell

7th edition

978-1337102100

More Books

Students also viewed these Accounting questions

Question

1. How is a central bank different from a typical commercial bank?

Answered: 1 week ago

Question

What is beacon marketing? What are digital wallets?

Answered: 1 week ago