1.What will the following code print? waterGlass.py waterMain.py import waterGlass class WaterGlass: def main(): Ben =...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
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... View the full answer
Related Book For
Microsoft Visual C# An Introduction to Object-Oriented Programming
ISBN: 978-1337102100
7th edition
Authors: Joyce Farrell
Posted Date:
Students also viewed these accounting questions
-
What will the following code display in message boxes? Dim intX As Integer = 1 Do MessageBox.Show(intX.ToString) intX = intX + 1 Loop Until intX > 5
-
What will the following code display? Dim intTotal As Integer Do While intTotal
-
What will the following code display? Dim intTotal As Integer Do MessageBox.Show(intTotal.ToString) intTotal = intTotal + 2 Loop Until intTotal >= 2
-
The following recreation demand function is for a beach: x = 4 (p/500) + q. The visitation amount is represented by x (times), the travel cost is represented by p (yen), and the water quality is...
-
The following T accounts show transactions that were recorded by Housing Locators, a firm that specializes in local housing renting. The entries for the first transaction are labeled with the letter...
-
Consider the following string of page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2. Complete a figure similar to Figure 8.14, showing the frame allocation for: a. FIFO (first-in-first-out) b. LRU...
-
a. Sketch possible arrangements for the piping and valves for Figure 14-6. Note that every tank needs to be able to receive fresh washwater or overflow from the next higher letter tank, except for...
-
As noted in this chapter, because of global competition, companies have become increasingly focused on reducing costs. To reduce costs and remain competitive, many companies are turning to...
-
On January 1 , 2 0 2 4 , Instaform, Incorporated, issued 1 0 % bonds with a face amount of $ 5 1 million, dated January 1 . The bonds mature in 2 0 4 3 ( 2 0 years ) . The market yield for bonds of...
-
Cecil C. Seymour is a 64-year-old widower. He had income for 2022 as follows: The cost of the annuity was $46,800, and Cecil was expected to receive a total of 260 monthly payments of $450. Cecil has...
-
Alpine produces a single product. The company's March 2018 income statement is as follows: Sales (600 x $60) Cost of goods sold Gross profit $36,000 - 33,000 $3,000 2,000 Selling and administrative...
-
A tow truck pulls a car 5 km along a horizontal road, using a cable whose tension is 850 N. Consider that the car is stuck and therefore the friction force exerted by the pavement is 250 N. a) How...
-
Question 5 1 kg of saturated water at 10 bar is heated to 400 C adiabatically. What is the amount of heat added through this process? A 2501 kJ B 3264 kJ (C) 763 kJ D) 4027 kJ 2 Points
-
An investor has a portfolio comprised of stock A, which has a beta of 0.60 and an expected return of 30%, and Treasury bills, which have an expected return of 1.9%. The portfolio has an expected...
-
Question 6 2 Points A Carnot heat engine has an efficiency of 40 %6. If the same engine was used as a Carnot refrigeration cycle what would be the coefficient of performance and the heat absorbed if...
-
What is critical chain management. How is it different from critical path management? Use your own words to show that you understand the definitions.
-
Use the Weatherbit API to obtain a 5-day weather forecast with High and Low-temperature information. You will need to register to obtain an API Key to use the Weatherbit API. Keys are generally made...
-
Privitera and Freeman (2012) constructed a scale to measure or estimate the daily fat intake of participants; the scale was called the estimated daily intake scale for fat (EDIS-F). To validate the...
-
The amount variable contains the string 3,123,560. Write the C++ code to remove the commas from the contents of the variable.
-
The instruction Brush your hair 5 times is an example of which structure? a. Control b. Repetition c. Selection d. Sequence
-
A problems _____________________ will answer the question What information will the computer need to know to display, print, or store the output items? a. Input b. Output c. Processing d. Purpose
-
Which of the following is false about perfect competition? a. Perfectly competitive firms sell homogeneous products. b. A perfectly competitive industry allows easy entry and exit. c. A perfectly...
-
What is a price taker?
-
What is total revenue?
Study smarter with the SolutionInn App