Write a class House defined as follows: A constructor that takes three arguments: an integer p,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
class House def initself p s c Constructor that takes two integers p and s and a string c and initia... View the full answer
Related Book For
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis
Posted Date:
Students also viewed these programming questions
-
Assume that you are the president of Highlight Construction Company. At the end of the first year of operations (December 31), the following financial data for the company are available: Cash...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
What is a derivative contract? Give an example. How are derivatives related to risk management?
-
A thin foil of certain stable isotope is irradiated by thermal neutrons falling normally on its surface. Due to the capture of neutrons a radionuclide with decay constant appears. Find the law...
-
Marston Company has outstanding accounts receivable totaling 4.5 million as of December 31 and sales on credit during the year of 20 million. There is also a credit balance of 18,000 in the allowance...
-
Figure 2.3 displays the frequency distribution from Example 2.5. Create a similar plot using ggplot () to display the relative frequency distribution for each treatment group instead of the frequency...
-
WinCo Foods, a large discount grocery retailer in the western United States, promotes itself as the lowest priced grocery retailer. In newspaper ads WinCo Foods published a price comparison for...
-
How does the standard define relevance and reliability? What must an auditor do if conditions indicate that a document may not be authentic or the terms in a document have been modified but that the...
-
Wedding Planners Limited (WP), owned by Anne and Francois Tremblay, provides wedding planning and related services. WP owns a building (the Pavilion) that has been custom-made for hosting weddings....
-
Critically analyze the service quality gaps affecting the co-creation of the customer experience chain and how the competitive service strategies afford the transition from service-dominant logic to...
-
What is the result of executing the Sounds program? A. The code runs and prints baa!. B. The Sheep class does not compile. C. The Sounds class does not compile. D. Neither class compiles. //...
-
Given the following two classes in the same package, what is the result of executing the Hug program? A. kitty - 5.0 B. The Kitten class does not compile. C. The Hug class does not compile. D. The...
-
Which of the following are true about the following code? (Choose two.) A. When you fill in both blanks with double, it prints 8.00.0 B. When you fill in both blanks with double, it prints 8.0 C....
-
How many Gems objects are eligible for garbage collection right before the end of the main() method? A. None B. One C. Two D. Three E. Four F. The code does not compile public class Gems { public...
-
What is the output of the Helicopter program? A. 5 B. 10 C. The code does not compile. D. The code compiles but produces a ClassCastException at runtime. E. None of the above. package flying; class...
-
In December, Joseph Blanchard became the controller of Carls- bad Home Care (CHC). After 10 years in the accounting depart- ment of a consumer products firm, Mr. Blanchard had decided to move into...
-
Illini Company, Inc. Balance Sheet as of 12/31/20X0 Assets Current Assets: Cash $1,500,000 Accounts receivable, net 18,000 Inventory 50,000 Total current assets 1,568,000 Equipment 90,000 Goodwill...
-
To delete an item from an ArrayList object, you use this method. a. Remove b. Delete c. Erase d. Get
-
This is a Java class that is designed to communicate with a specific DBMS. a. JDBC driver b. DBMS Superclass c. DBMS Subclass d. Stream converter
-
Write a class named PhoneBookEntry that has fields for a persons name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that...
-
A friend is standing behind a large tree and yelling. You can hear him, but not see him. Why?
-
Light of wavelength \(\lambda\) is incident on an aperture of width \(a\), producing diffraction. Describe the change(s) in the diffracted waves \((a)\) when the aperture width is doubled and \((b)\)...
-
Coherent green light of wavelength \(530 \mathrm{~nm}\) passes through two narrow slits for which the center-to-center separation distance is \(100 \mu \mathrm{m}\). What is the difference in phase...
Study smarter with the SolutionInn App