Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class House defined as follows: A constructor that takes three arguments: an integer p, an integer s, and a string c. The

 

Write a class House defined as follows: A constructor that takes three arguments: an integer p, an integer s, and a string c. The values of those three local variables must be assigned to three attributes: self.price, self.sqft, and self.city. A method_str_ that returns a string with the three attribute values, each on a new line. A method unitPrice that returns the price per square feet (obtained by dividing self.price by self.sqft), rounded as an integer. Outside (and after) the block of code defining the class House, write the fol- lowing tests: Create an object h1 by calling the constructor of the class House with the three argument values 240000, 1400, and "Philadelphia'. Print h1. Print hl.unitPrice (). You must obtain the following result: 240000 1400 Philadelphia Create a second object h2 by calling the constructor of the class House with the three argument values 160000, 1000, and 'New York. Create a dictionary dico. Add hi at the key 'Paul' and h2 at the key 'Mary'. Print the data stored at the key "Mary' 3. Write a function displayUnit that takes as an argament a dictionary d where the keys are first names (strings) and the value at each key is an object of the class House defined in Question 2. The function must print each key followed by the price per square feet of the house at this key, each on a new line. The call of this function with the dictionary dico created in Question 2. displayUnit (dico) must give the following result, exactly: Unit price of Paul's house: 171 Unit price of Mary's house: 160

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

Step: 1

class House def initself p s c Constructor that takes two integers p and s and a string c and initia... 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

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

More Books

Students also viewed these Programming questions