143k views
1 vote
Im having trouble with this assignment and am running out of time due to work. Im stuck on a few areas and need help drastically

For this assignment, write a program that will allow a user to book a stay at one of four (4) offered dwellings, and calculate the base price for the entire stay. The program logic will need to define a "Dwelling" data type that will hold the following information about a dwelling:

Id - Unique identifier for the dwelling (whole number)
City - The name of the city where the dwelling is located
State - Abbreviation of US state where dwelling is located
Bedrooms - Number of bedrooms available in the dwelling (whole number)
Bathrooms - Number of bathrooms available in the dwelling (whole number)
NightlyRate - The price per night to stay at the dwelling (whole number)
A pseudo-constructor should be defined for the "Dwelling" data type. The pseudo-constructor definition should include a parameter for each "Dwelling" member variable in the order they are numbered above.

The program logic will also need to instantiate four (4) "Dwelling" objects in the main function with the following information using the pseudo-constructor:

Dwelling Id City State Abbreviation Number of Bedrooms Number of Bathrooms Nightly Rate
1 Los Angeles CA 4 2 $300
2 New York NY 3 1 $245
3 Chicago IL 4 1 200
4 Seattle WA 5 3 375
Note: The information initialized for each dwelling object listed above should be hard-codedLinks to an external site.. The user will not input this information.

After each "Dwelling" object is instantiated, all of the dwelling options should be displayed to the user. The user will then select one of the dwellings by Id and then enter the number of nights to stay. The program will then display the user's selection back to them, the number of nights entered, and the calculated base price of the stay.

Example Output 1 (input in bold and underlined for clarity):
Welcome to Book-A-Dwelling!

Here are your dwelling options:

Dwelling 1
Location: Los Angeles, CA
4 Bedrooms, 2 Baths
Nightly Rate: $300

Dwelling 2
Location: New York, NY
3 Bedrooms, 1 Baths
Nightly Rate: $245

Dwelling 3
Location: Chicago, IL
4 Bedrooms, 1 Baths
Nightly Rate: $200

Dwelling 4
Location: Seattle, WA
5 Bedrooms, 3 Baths
Nightly Rate: $375

Please select a dwelling number from the list above
3

Excellent choice! How many nights will you stay?
2

Booking Summary:
Dwelling 3
Location: Chicago, IL
4 Bedrooms, 1 Baths
Nightly Rate: $200

Staying for 2 nights

Base price of your stay: $400

User TyC
by
7.0k points

1 Answer

2 votes

Here's an example code in Python that meets your assignment's requirements!

class Dwelling:

def __init__(self, dwelling_id, city, state, bedrooms, bathrooms, nightly_rate):

self.id = dwelling_id

self.city = city

self.state = state

self.bedrooms = bedrooms

self.bathrooms = bathrooms

self.nightly_rate = nightly_rate

dwelling1 = Dwelling(1, "Los Angeles", "CA", 4, 2, 300)

dwelling2 = Dwelling(2, "New York", "NY", 3, 1, 245)

dwelling3 = Dwelling(3, "Chicago", "IL", 4, 1, 200)

dwelling4 = Dwelling(4, "Seattle", "WA", 5, 3, 375)

print("Welcome to Book-A-Dwelling!\\")

print("Here are your dwelling options:\\")

print(f"Dwelling {dwelling1.id}")

print(f"Location: {dwelling1.city}, {dwelling1.state}")

print(f"{dwelling1.bedrooms} Bedrooms, {dwelling1.bathrooms} Baths")

print(f"Nightly Rate: ${dwelling1.nightly_rate}\\")

print(f"Dwelling {dwelling2.id}")

print(f"Location: {dwelling2.city}, {dwelling2.state}")

print(f"{dwelling2.bedrooms} Bedrooms, {dwelling2.bathrooms} Baths")

print(f"Nightly Rate: ${dwelling2.nightly_rate}\\")

print(f"Dwelling {dwelling3.id}")

print(f"Location: {dwelling3.city}, {dwelling3.state}")

print(f"{dwelling3.bedrooms} Bedrooms, {dwelling3.bathrooms} Baths")

print(f"Nightly Rate: ${dwelling3.nightly_rate}\\")

print(f"Dwelling {dwelling4.id}")

print(f"Location: {dwelling4.city}, {dwelling4.state}")

print(f"{dwelling4.bedrooms} Bedrooms, {dwelling4.bathrooms} Baths")

print(f"Nightly Rate: ${dwelling4.nightly_rate}\\")

dwelling_choice = int(input("Please select a dwelling number from the list above: "))

num_nights = int(input("\\Excellent choice! How many nights will you stay? "))

if dwelling_choice == 1:

chosen_dwelling = dwelling1

elif dwelling_choice == 2:

chosen_dwelling = dwelling2

elif dwelling_choice == 3:

chosen_dwelling = dwelling3

else:

chosen_dwelling = dwelling4

total_price = chosen_dwelling.nightly_rate * num_nights

print("\\Booking Summary:")

print(f"Dwelling {chosen_dwelling.id}")

print(f"Location: {chosen_dwelling.city}, {chosen_dwelling.state}")

print(f"{chosen_dwelling.bedrooms} Bedrooms, {chosen_dwelling.bathrooms} Baths")

print(f"Nightly Rate: ${chosen_dwelling.nightly_rate}\\")

print(f"Staying for {num_nights} nights\\")

print(f"Base price of your stay: ${total_price}")

(This program defines a Dwelling class with the given member variables, and creates four objects with the given information using the pseudo-constructor. The program then displays the list of dwelling options to the user and prompts them to select a dwelling and enter the number of nights they will stay. The program calculates the base price of the stay and displays a summary of the user's selection and the calculated base price.)

User Kawty
by
7.5k points