CS303E Guest Star 1

Instructor: Dr. Bill Young
Due Date: Never!

Copyright © Dewayne Benson. All rights reserved.

Practice with Classes: Barbie's Dreamhouse!

Barbie has graciously allowed us to work our Python magic on her Dreamhouse. Since Barbie loves to throw fabulous parties, she wants a Dreamhouse that can handle everything from the guest list to adding entire new rooms. Barbie insists on everything being picture-perfect!

Unfortunately for her, the rating of her Dreamhouse, and thus the success of her party, is dependent on a cleanliness score, which is constantly at risk thanks to guests who decide on a whim whether they want to behave.

In this exercise, you will implement this Dreamhouse class, and hope for the best for our friend Barbie!

Specifications

Here are the requirements Barbie has outlined for the Dreamhouse:
  • Implement your Dreamhouse as a class, with the following private data members:
  • We need the following methods in the Dreamhouse:

    Template:

    Barbie, the good samaritan she is, gave us the template for the Dreamhouse class. We simply need to fill in the bodies of the methods!
    import random
    
    class Dreamhouse:
    
        def __init__(self, owner = "Barbie"):
            """
            Initializes a Dreamhouse object with an owner (default is
            "Barbie"). Sets up the house's attributes such as owner,
            room count, blocked guest, party size, cleanliness, and
            two room slots.
            """
            pass
        
        def getCleanliness(self):
            """
            Returns the current cleanliness level of the Dreamhouse
            (an integer between 0 and 100).
            """
            pass
    
        def getOwner(self):
            """
            Returns the name of the current owner of the Dreamhouse.
            """
            pass
    
        def setOwner(self, newOwner = "Barbie"):
            """
            Sets a new owner for the Dreamhouse (default is "Barbie").
            """
            pass
    
        def setBlock(self, newBlock):
            """
            Sets a blocked guest who is not allowed to enter the Dreamhouse.
            """
            pass
    
        def __str__(self):
            """
            Returns a string representation of the Dreamhouse, including
            the owner's name, cleanliness rating, party size, and details
            of the two rooms. The cleanliness contributes to the overall
            dreamhouse rating.
            """
            pass
    
        def enter(self, name):
            """
            Increases the party size by 1 when a guest enters the house. 
            If the guest is blocked, they are not allowed to enter, and
            a message is printed.
            """
            pass
    
        def evict(self, name):
            """
            Evicts a guest, reduces the party size by 1, and adjusts
            the cleanliness based on how clean or messy the guest was
            (randomly decided between -25 to 25).
            """
            pass
    
        def addRoom(self, roomName):
            """
            Adds a new room to the Dreamhouse. There are only two room slots
            available, so if both rooms are already taken, no new rooms can
            be added. The addition of a room increases the Dreamhouse's
            rating by 1 star.
            """
            pass
    
        def crashParty(self, numKen):
            """
            Simulates Kens crashing the party. For each Ken, the method enters
            and then evicts them.
            """
            pass
    
    

    Expected Output

    Barbie's generosity knows no bounds, as she provided us with the expected behavior for the Dreamhouse!:
    >>> from Dreamhouse.py import *
    >>> myCrib = Dreamhouse()
    >>> print(myCrib)
    
    ** Barbie's Dreamhouse **
    =========================
    Rating: 2.91 / 5.00
    Party Size: 0
    Room 1: None
    Room 2: None
    =========================
    
    >>> myCrib.getCleanliness()
    97
    >>> myCrib.enter("Midge")
    Midge came to the party!
    
    >>> myCrib.enter("Nicki Minaj")
    Nicki Minaj came to the party!
    
    >>> myCrib.evict("Midge")
    Midge has overstayed their welcome. Bye-bye!
    Midge was a clean guest! 5 added to cleanliness.
    
    >>> myCrib.evict("Nicki Minaj")
    Nicki Minaj has overstayed their welcome. Bye-bye!
    Ugh! Nicki Minaj left behind a mess. 13 subtracted from cleanliness.
    
    >>> print(myCrib)
    
    ** Barbie's Dreamhouse **
    =========================
    Rating: 2.61 / 5.00
    Party Size: 0
    Room 1: None
    Room 2: None
    =========================
    
    >>> myCrib.setOwner("Billie")
    print(myCrib)
    
    ** Billie's Dreamhouse **
    =========================
    Rating: 2.61 / 5.00
    Party Size: 0
    Room 1: None
    Room 2: None
    =========================
    
    >>> myCrib.addRoom("Jacuzzi")
    >>> myCrib.addRoom("Arcade")
    >>> myCrib.enter("Kim Kardashian")
    Kim Kardashian came to the party!
    
    >>> print(myCrib)
    
    ** Billie's Dreamhouse **
    =========================
    Rating: 4.61 / 5.00
    Party Size: 1
    Room 1: Jacuzzi
    Room 2: Arcade
    =========================
    
    >>> myCrib.getOwner()
    'Billie'
    >>> myCrib.setOwner()
    >>> myCrib.setBlock("Cardi B.")
    >>> myCrib.enter("Cardi B.")
    Cardi B. is on the premise. Police have been called.
    
    >>> myCrib.crashParty(2)
    Oh no! Kens are crashing the party!
    
    Ken came to the party!
    Ken has overstayed their welcome. Bye-bye!
    Ugh! Ken left behind a mess. 8 subtracted from cleanliness.
    
    Ken came to the party!
    Ken has overstayed their welcome. Bye-bye!
    Ken was a clean guest! 7 added to cleanliness.
    
    >>> myCrib.setBlock("Ken")
    >>> myCrib.crashParty(3)
    Oh no! Kens are crashing the party!
    They broke through the block!
    
    Ken came to the party!
    Ken has overstayed their welcome. Bye-bye!
    Ugh! Ken left behind a mess. 1 subtracted from cleanliness.
    
    Ken came to the party!
    Ken has overstayed their welcome. Bye-bye!
    Ken was a clean guest! 22 added to cleanliness.
    
    Ken came to the party!
    Ken has overstayed their welcome. Bye-bye!
    Ugh! Ken left behind a mess. 14 subtracted from cleanliness.
    
    >>> print(myCrib)
    
    ** Barbie's Dreamhouse **
    =========================
    Rating: 4.58 / 5.00
    Party Size: 1
    Room 1: Jacuzzi
    Room 2: Arcade
    =========================
    
    >>>
    

    Turning In the Exercise:

    You won't need to turn this in, but you should be proud of your work! For the cherry on top, slot in this header in your file:
    # Exercise: Guest Star 1
    # File: Dreamhouse.py
    # Student: 
    # UT EID:
    # Course Name: CS303E
    # 
    # Date Created:
    # Description of Program: