Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10, Problem 5MC
By doing this, you can hide a class’s attribute from code outside the class.
a. avoid using the self parameter to create the attribute
b. begin the attribute’s name with two underscores
c. begin the name of the attribute with private_ _
d. begin the name of the attribute with the @ symbol
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule01:39
Students have asked these similar questions
Please do not give solution in image format thanku.
****PYTHON
In the class Car(), update the class structure to include the attributes and methods
*__init__(self) initialize the class and create the attribute miles with a default integer 0.
*drive(self, distance) Which updates the miles attribute with current miles + distance parameter. reverse(self, distance) Which updates the miles attribute with the current miles — distance parameter.
*get_odometer(self) returns miles attribute. honk_horn(self, times) accepts the number of times wanted to honk the horn and is defaulted to 1. It outputs the message honk! without a trailing space. If times > 1, then multiple the message by times to output a message: honk! honk!.
*result(self) - outputs message “# miles driven”. (where the # sign represents the number of miles attribute driven.
the main() function with three integers which represent the miles to drive forward, and to drive in reverse as user inputs, also how many times the horn…
Please do not give solution in image format thanku.
****PYTHON
In the class Car(), update the class structure to include the attributes and methods
__init__(self) initialize the class and create the attribute miles with a default integer 0.
drive(self, distance) Which updates the miles attribute with current miles + distance parameter. reverse(self, distance) Which updates the miles attribute with the current miles — distance parameter.
get_odometer(self) returns miles attribute. honk_horn(self, times) accepts the number of times wanted to honk the horn and is defaulted to 1. It outputs the message honk! without a trailing space. If times > 1, then multiple the message by times to output a message: honk! honk!.
Reported(self) Outputs message: # miles have been driven. (# stands for attribute miles)
the main() function with three integers which represent the miles to drive forward, and to drive in reverse as user inputs, also how many times the horn should be honked. Using the…
In python, complete both sections please
Section 5: The StudentAccount class This class represents a financial status of the student based on enrollment and is saved to a Student object as an attribute. This class should also contain an attribute that stores the price per credit, initially $1000/credit. This cost can change at any time and should affect the future price of enrollment for ALL students. Attributes Type Name Description Student student The Student object that owns this StudentAccount. numerical balance The balance that the student has to pay. dict loans A dictionary that stores Loan objects accessible by their loan_id. Methods Type Name Description numerical makePayment(self, amount) Makes a payment towards the balance. numerical chargeAccount(self, amount) Adds an amount towards the balance. Special methods Type Name Description str __str__(self) Returns a formatted summary of the loan as a string. str __repr__(self) Returns the same formatted summary as __str__.…
Chapter 10 Solutions
Starting Out with Python (4th Edition)
Ch. 10.1 - What is an object?Ch. 10.1 - Prob. 2CPCh. 10.1 - Why is an object's internal data usually hidden...Ch. 10.1 - What are public methods? What are private methods?Ch. 10.2 - You hear someone make the following comment: "A...Ch. 10.2 - In this chapter, we use the metaphor of a cookie...Ch. 10.2 - What is the purpose of the _ _init_ _ method? When...Ch. 10.2 - Prob. 8CPCh. 10.2 - In a Python class, how do you hide an attribute...Ch. 10.2 - What is the purpose of the _ _str_ _ method?
Ch. 10.2 - Prob. 11CPCh. 10.3 - What is an instance attribute?Ch. 10.3 - Prob. 13CPCh. 10.3 - What is an accessor method? What is a mutator...Ch. 10.4 - Prob. 15CPCh. 10.4 - Prob. 16CPCh. 10.4 - When designing an object-oriented application, who...Ch. 10.4 - How do you identify the potential classes in a...Ch. 10.4 - What are a classs responsibilities?Ch. 10.4 - What two question should you ask to determine a...Ch. 10.4 - Will all of a class's action always be directly...Ch. 10 - The _______ programming practice is centered on...Ch. 10 - The ___________ programming practice is centered...Ch. 10 - A(n) _____ is a component of a class that...Ch. 10 - Prob. 4MCCh. 10 - By doing this, you can hide a classs attribute...Ch. 10 - Prob. 6MCCh. 10 - A(n) ________ method stores a value in a data...Ch. 10 - Prob. 8MCCh. 10 - If a class has a method named _ _str_ _ , which of...Ch. 10 - A set of standard diagrams for graphically...Ch. 10 - In one approach to identifying the classes in a...Ch. 10 - Prob. 12MCCh. 10 - The practice of procedural programming is centered...Ch. 10 - Object reusability has been a factor in the...Ch. 10 - It is a common practice in object-oriented...Ch. 10 - Prob. 4TFCh. 10 - Starting an attribute name with two underscores...Ch. 10 - You cannot directly call the _ _ str _ _ method.Ch. 10 - One way to find the classes needed for an...Ch. 10 - Prob. 1SACh. 10 - Why should an object's data attributes be hidden...Ch. 10 - What is the difference between a class and an...Ch. 10 - The following statement calls an object's method....Ch. 10 - Prob. 5SACh. 10 - In a Python class, how do you hide an attribute...Ch. 10 - Prob. 7SACh. 10 - Suppose my_car is the name of a variable that...Ch. 10 - Prob. 2AWCh. 10 - Look at the following description of a problem...Ch. 10 - Pet Class The Pet class Write a class named Pet,...Ch. 10 - Car Class Write a class named Car that has the...Ch. 10 - Personal Information Class Design a class that...Ch. 10 - Employee Class Write a class named Employee that...Ch. 10 - RetailItem Class Write a class named RetailItem...Ch. 10 - Patient Charges Write a class named Patient that...Ch. 10 - Employee Management System This exercise assumes...Ch. 10 - Cash Register This exercise assumes you have...Ch. 10 - Trivia Game In this programming exercise, you will...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Open the Code Pad in the better-ticket-machine project. Type the following in the Code Pad:
Take care to typ...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Sales Prediction The East Coast sales division of a company generates 62 percent of total sales. Based on that ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
_____ is the only language computers can process directly, without any conversion required.
Starting Out With Visual Basic (8th Edition)
Define each of the following terms: entity type entity-relationship model entity instance Attribute relationshi...
Modern Database Management
If you use a variable in a function definition, where should you declare the variable? In the function definiti...
Problem Solving with C++ (10th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- User: Make a class called User. Create two attributes called first_name and last_name, and then create several other attributes that are typically stored in a user profile. Makea method called describe_user() that prints a summary of the user's information. Make another method called greet_user() that prints a personalized greeting to the user.Then - Create several instances representing different users, and call both methods for each user. Admin: write a class called Admin that inherits from the User class. Add an attribute,privileges, that stores a list of strings like "can add post”, "can delete post”, "can banuser”, and so on. Write a method called show_privileges() that lists the administrator'sset of privileges. Then - Create an instance of Admin, and call your method.arrow_forwardCreate a class named “Rectangle” having length and width as attribute. There should be behaviors to set the values of length and width (individually and collectively), and get their values individually. There should also be behavior to display the perimeters and area of the rectangle. Note ( The Question of OOP )arrow_forwardPlease complete the following tasks: Write a class “Actor” that contains two attributes with the appropriate level of visibility explicitly defined. “Name” which is a String, Private, “NumberofAwards” which is an integer, private Write a default Constructor for this class that initializes the name to “Bob Smith” , and the number of awards to 0. Write an overload the constructor for this class that accepts actor’s name as a parameter Write accessor methods for each of the attributes. Write a method “winsAnOscar” that increases the number of awards by one and prints “The crowd applauds for <actor’s name>!” Be sure to use accessors where appropriate. Make sure your header is complete, with the appropriate level of visibility and any required keywords.arrow_forward
- Create a class that contains an address book entry and name it AddressBook. The table below describes the information that an address book entry has. Attributes/Field Description Name Name of the person in the address book Address Address of the person Mobile Number Mobile number of the person Email Address Email address of the person The class definition should contain the following: Attributes Constructor Accessors and mutators Test Stem / Question Choices 1: How many attributes should be defined in AddressBook class? A: 1 B: 2 C: 3 D: 4 E: None of the above 2: How many accessors should be defined in AddressBook class? A: 1 B: 2 C: 3 D: 4 E: None of the above 3: How many mutators should be defined in AddressBook class? A: 1 B: 2 C: 3 D: 4 E: None of the above 4: What is the name of the Constructor? A: AddressBook B: AddressBook() C: public AddressBook…arrow_forwardWhich of the following statements is false? a. A class can contain only one constructor. b. An example of a behavior is the SetTime method in a Time class. c. An object created from a class is referred to as an instance of the class. d. An instance of a class is considered an object.arrow_forwardCreate a Book class with the following attributes: title, author (an instance of the Author class), publication_date, and price. Also, include a class variable all_books that keeps a list of all book instances created.The Book class should have: A __str__ method to represent the book in a user-friendly format. A __eq__ method to compare two books. Two books are considered the same if they have the same title and author. A __lt__ method to compare two books based on their publication dates. A class method get_all_books that returns a list of all books in the library. A static method most_expensive_book that takes a list of book instances and returns the most expensive one. Finally, create a Library class that manages books and authors. This class should include the following: An attribute collection to store the books in the library. A method add_book to add a new book to the library. If the book already exists in the library (based on the __eq__ method from the Book class), it…arrow_forward
- Create the class Student, which must have a normalconstructor and at least 5 attributes Attributes ; ID, name, Semester Gender, Age JAVAarrow_forwardCreate a class named Person that holds the following fields: two String objectsfor the person’s first and last name and a LocalDate object for the person’sbirthdate. Create a class named Couple that contains two Person objects. Create aclass named Wedding for a wedding planner that includes the date of the wedding,the names of the Couple being married, and a String for the location. Provideconstructors for each class that accept parameters for each field, and provide getmethods for each field. Then write a program that creates two Wedding objectsand in turn passes each to a method that displays all the details. Save the files asPerson.java, Couple.java, Wedding.java, and TestWedding.java.arrow_forwardCreate a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaidaarrow_forward
- Implement a Person class with the following attributes: Name: String Place of Birth: String Birthdate: Date Gender: String The constructor will receive the name and birthday date. The gender and the place of birth should be initialized as empty strings. Make the attributes private and create getter and setter methods. Write a __str__ method that prints the name and the age of the person (check the testcase for the format). To calculate the age just subtract the year of birth to the current year (don't worry about the day/month, it is not an objective of this exercise). A datetime object has a year attribute that is public. To get the current date, use: datetime.date.today() which also has a year attribute.arrow_forwardQuestion 6 sm.True or False, BindingContext between two objects can be two-way. In that if either object's value changes, it effects the other object. An object can be a control (view) or class object. Question 6 options: True False Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardIn python, using class: 1) Create a 'bank account' that let's the user have both withdrawals and deposits. Each person should be their own object so that each deposit and withdrawal should only affect the individual bank accounts, not each other. Make a attribute inside of the __init__ to set the balance to zero (default). If during withdrawal, they reach "0", use a conditional to let them know they have no money in the account. 2) Create another 'bank account' where it is a joint account and anyone can withdraw or deposit to the amount. If they reach "0", use a conditional to let them know they have no money in the account.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY