>>> roman_candle = RomanCandle ("example") >>> launches = roman_candle. launch_several (4) >>> roman_candle.noise_made 360 >>> roman_candle.noise_complaints Θ >>> print(roman_candle.calculate_complaints()) Received 1 new noise complaints. Explanation: - after 4 launches, the noise is 150 +30 + 150 + 30 = 360 - before .calculate_complaints() is called, the noise_complaints attribute is 0 - when .calculate_complaints() is called: 360 // 250 = 1, and noise_complaints is currently 0, so there is 1 - 0 = 1 new noise complaints noise_complaints // 4 = 1 // 4 = 0, so cops are not called >>> roman_candle.noise_complaints 1 >>> launches = roman_candle. launch_several (10) >>> roman_candle.noise_made 1260 >>> print(roman_candle.calculate_complaints()) COPS CALLED!! Received 4 new noise complaints. Explanation: - when .calculate_complaints() is called, noise_complaints is set to 1 - after 10 more launches, the noise is 360 + 150 + 30+ ... + 30 = 1260 - 1260 // 250 = 5, and noise_complaints is currently 1, so there are 5 - 1 = 4 new noise complaints noise_complaints // 4 = 5 // 4 = 1, cops_called is currently 0, and 1 > 0, so cops are called

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter3: Using Methods, Classes, And Objects
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

class Firework:
    """
    Implementation of the base Firework class
    """

    def __init__(self, brand):
        """ Constructor """
        self.brand = brand
        self.brightness = 5
        self.launches = 0
        self.noise_made = 0
        self.noise_complaints = 0

    def launch(self):
        """
        Launch a firework, updates noise_made and returns string
        """
        self.launches += 1
        if self.launches % 2 == 1:
            execute = 'successful'
            noise = 150
        else:
            execute = 'dud'
            noise = 30
        self.noise_made += noise
        return ("The " + self.brand + " firework was launched and it was a "
            + execute + " launch. It created "
            + str(noise) + " decibels of noise.")
        
    def launch_several(self, amount):
        """
        Launches fireworks `amount` of times, returns the full string
        """
        results = ""
        for _ in range(amount):
            results += self.launch() + "\n"
        return results.rstrip("\n")

class Firecracker(Firework):
    """
    Implementation of the Firecracker class
    """

    def __init__(self, brand):
        """ Constructor, set initial brightness """
        super().__init__(brand) 
        self.brightness = 3

    def calculate_complaints(self):
        """
        Calculates the number of noise complaints received
        """
        new_complaints = self.noise_made // 250 - self.noise_complaints
        if new_complaints > 0:
            self.noise_complaints += new_complaints
            return "Received " + str(new_complaints) + " new noise complaints."
        else:
            return "No new complaints!"

        
class RomanCandle(Firecracker):
    """
    Implementation of the RomanCandle class
    """

    def __init__(self, brand):
        """ Constructor, set initial brightness """
        self.cops_called = 0
        super().__init__(brand) 

    def calculate_complaints(self):
        """ Returns a message describing the number of complaints """
        if self.noise_complaints // 4 > self.cops_called : 
            self.cops_called += 1
            return 'COPS CALLED!!\n' + super().calculate_complaints()
        else:
            return super().calculate_complaints()

360
0
Received 1 new noise complaints.
1
1260
Received 4 new noise complaints.
0


** Process exited - Return Code: 0 **
Press Enter to exit terminal

only fix def calculate_complaints(self) in side of class RomanCandle(Firecracker)

>>> roman_candle = RomanCandle ("example")
>>> launches = roman_candle. launch_several (4)
>>> roman_candle.noise_made
360
>>> roman_candle.noise_complaints
Θ
>>> print(roman_candle.calculate_complaints())
Received 1 new noise complaints.
Explanation:
- after 4 launches, the noise is 150 +30 + 150 + 30 = 360
- before .calculate_complaints() is called, the noise_complaints attribute is 0
-
when .calculate_complaints() is called: 360 // 250 = 1, and noise_complaints
is currently 0, so there is 1 - 0 = 1 new noise complaints
noise_complaints // 4 = 1 // 4 = 0, so cops are not called
>>> roman_candle.noise_complaints
1
>>> launches = roman_candle. launch_several (10)
>>> roman_candle.noise_made
1260
>>> print(roman_candle.calculate_complaints())
COPS CALLED!!
Received 4 new noise complaints.
Explanation:
- when .calculate_complaints() is called, noise_complaints is set to 1
- after 10 more launches, the noise is 360 + 150 + 30+ ... + 30 = 1260
-
1260 // 250 = 5, and noise_complaints is currently 1, so there are 5 - 1 = 4
new noise complaints
noise_complaints // 4 = 5 // 4 = 1, cops_called is currently 0, and 1 > 0, so
cops are called
Transcribed Image Text:>>> roman_candle = RomanCandle ("example") >>> launches = roman_candle. launch_several (4) >>> roman_candle.noise_made 360 >>> roman_candle.noise_complaints Θ >>> print(roman_candle.calculate_complaints()) Received 1 new noise complaints. Explanation: - after 4 launches, the noise is 150 +30 + 150 + 30 = 360 - before .calculate_complaints() is called, the noise_complaints attribute is 0 - when .calculate_complaints() is called: 360 // 250 = 1, and noise_complaints is currently 0, so there is 1 - 0 = 1 new noise complaints noise_complaints // 4 = 1 // 4 = 0, so cops are not called >>> roman_candle.noise_complaints 1 >>> launches = roman_candle. launch_several (10) >>> roman_candle.noise_made 1260 >>> print(roman_candle.calculate_complaints()) COPS CALLED!! Received 4 new noise complaints. Explanation: - when .calculate_complaints() is called, noise_complaints is set to 1 - after 10 more launches, the noise is 360 + 150 + 30+ ... + 30 = 1260 - 1260 // 250 = 5, and noise_complaints is currently 1, so there are 5 - 1 = 4 new noise complaints noise_complaints // 4 = 5 // 4 = 1, cops_called is currently 0, and 1 > 0, so cops are called
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT