Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 10, Problem 6MC
Program Description Answer
Accessor method is used to return a value from the method, but it will not change the value.
Hence, the correct answer is option “D”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Book Donation App
Create a book-app directory. The app can be used to manage book donations and track donors and books. The catalog is implemented using the following classes:
1. The app should have donors-repo.js to maintain the list of donors and allow adding, updating, and deleting donors. The donor object has donorID, firstName, lastName, and email properties. This module should implement the following functions:
• getDonor(donorId): returns a donor by id.
• addDonor(donor): adds a donor to the list of donors; donorID should be autoassigned a random number.
• updateDonor(donor): updates the donor having the matching donorID.
• deleteDonor(donorID): delete the donor with donorID from the list of donors, only if they are not associated with any books.
2. The app should have books-repo.js to maintain the list of donated books and allow adding, updating, and deleting books. The book object has bookID, title, authors, and donorID properties.
• donorID references the book’s donor. This…
A. Car Class
Create a Python Program where you write a class
named Car that has the following data attributes:
• _ _year_model (for the car's year model)
• __make (for the make of the car)
• _ _speed (for the car's current speed)
The Car class should have an _init_ method that
accepts the car's year model and make as arguments.
These values should be assigned to the object's
_year_model and
make data attributes. It should
also assign 0 to the __speed data attribute.
The class should also have the following methods:
accelerate()
The accelerate method should add 5 to the speed data
attribute each time it is called.
brake()
The brake method should subtract 5 from the speed
data attribute each time it is called.
• get_speed()
The get_speed method should return the current speed.
Next, design a program that creates a Car object then
calls the accelerate method five times. After each call
to the accelerate method, get the current speed of the
car and display it. Then call the brake method…
In java language
Chapter 10 Solutions
Starting Out with Python (3rd Edition)
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 - What is an object?Ch. 10.4 - Prob. 2CPCh. 10.4 - Why is an object's internal data usually hidden...Ch. 10.4 - What are public methods? What are private methods?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 - 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...
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
- Pet ClassDesign a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird". age: The age field holds the pet’s age. The Pet class should also have the following methods: setName: The setName method stores a value in the name setType: The setType method stores a value in the type setAge: The setAge method stores a value in the age getName: The getName method returns the value of the name getType: The getType method returns the value of the type getAge: The getAge method returns the value of the age Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen. *** I need help…arrow_forwardPet ClassDesign a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird". age: The age field holds the pet’s age. The Pet class should also have the following methods: setName: The setName method stores a value in the name setType: The setType method stores a value in the type setAge: The setAge method stores a value in the age getName: The getName method returns the value of the name getType: The getType method returns the value of the type getAge: The getAge method returns the value of the age Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen. The output Should be…arrow_forwardScores Class Write a class named Scores which should have the following attribute: • _scores (a list to hold test scores, 0 - 100. Initially empty. ) The Scores class should have an _init__ method that creates the _scores attribute. It should also have the following methods: • add_score: this method adds a score to the __scores list. It accepts a single score as it's' only argument. • get_average: this method accepts no arguments. If _scores is empty, this method returns -1. Otherwise, it returns the average of all scores in _scores. • get_high_score: this method accepts no arguments. if scores is empty, this method returns -1. Otherwise, it returns the highest score in __scores. • get_low_score: this method accepts no arguments. if scores is empty, this method returns -1. Otherwise, it returns the lowest score in scores. • _str_: This method returns a string similar to the following (assuming the _scores contains 89, 77, 93): Once you have written the class, write a program that…arrow_forward
- #employee.py class Employee: def__init__(self,Emp_name,Emp_id): self.__Emp_name=Emp_name self.__Emp_id=Emp_id defset_Empname(self,Emp_name): self.__Emp_name=Emp_name defset_Empid_number(self,Emp_id): self.__Emp_id=Emp_id defget_Empname(self): returnself.__Emp_name defget_Empid_number(self): returnself.__Emp_id class ProductionWorker(Employee): def__init__(self,Emp_name,Emp_id,Emp_shift, Emp_pay_rate): Employee.__init__(self,Emp_name,Emp_id) self.__Emp_shift=Emp_shift self.__Emp_pay_rate=Emp_pay_rate defset_Empshift_number(self,Emp_shift): self.__Emp_shift=Emp_shift defset_Emppay_rate(self,Emp_pay_rate): self.__Emp_pay_rate=Emp_pay_rate defget_Empshift_number(self): returnself.__Emp_shift defget_Emppay_rate(self): returnself.__Emp_pay_rate def main(): Employee_name='' Employee_id='' Employee_shift=0 Employee_pay=0.0 Employee_name=input('Enter the employee name: ') Employee_id=input('Enter the employee ID number: ') Employee_shift=int(input('Enter the employee shift number: '))…arrow_forwardRetailItem ClassWrite a class named RetailItem that holds data about an item in a retail store. The class should store the following data in attributes: item description, units in inventory, and price. Once you have written the class, write a program that creates three RetailItem objects and stores the following data in them: Description Units in Inventory Price Item #1 Jacket 12 59.95 Item #2 Designer Jeans 40 34.95 Item #3 Shirt 20 24.95arrow_forwardPersonal Information Class: Design a class called Employee that holds the following data about an employee: name ID number Department Job Title Class. Store your class in a separate file called employee.py. Your class will have an initializer method that will be passed the information entered by the user as arguments. Write appropriate accessor and mutator methods for each data attribute. Write a __str__ method to print the contents of the class (see example of __str__ on p. 523). Main program: Your main program should create three instances of the class. Your program should get the information from the user and pass it as parameters to the initializer method. Using the __str__ method invoked by the print function, the program should display the personal information for the three individuals. Output and Sample Dialog: Enter employee name: Mary Smith Enter employee ID: 123456 Enter department: Accounting Enter position: Accountant Enter employee name: Joe Morales Enter…arrow_forward
- 7. Employee Management System This exercise assumes you have created the Employee class for Programming Exercise 4. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. The program should present a menu that lets the user perform the following actions: Look up an employee in the dictionary Add a new employee to the dictionary Change an existing employee’s name, department, and job title in the dictionary Delete an employee from the dictionary Quit the program When the program ends, it should pickle the dictionary and save it to a file. Each time the program starts, it should try to load the pickled dictionary from the file. If the file does not exist, the program should start with an empty dictionary.arrow_forwardTrue/ False 1- Class objects can be defined prior to the class declaration. 2- You must use the private access specification for all data members of a class. 3- If an array is partially initialized, the uninitialized elements will be set to zero. 4- A vector object automatically expands in size to accommodate the items stored in it. 5- With pointer variables, you can access but not modify data in other variables. 6- Assuming myValues is an array of int values and index is an int variable, both of the following statements do the same thing. 1. cout header file. 15- To solve a problem recursively, you must identify at least one case in which the problem can be solved without recursion.arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forward
- Month Class Exceptions Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example, Janauary would be 1, February would be 2, and so forth. In addition, provide the following methods: A no-arg constructor that sets the monthNumber field to 1. A constructor that accepts the number of the month as an argument. It should set the monthNumber value to the value passed as the argument. If a value less than 1 or greater than 12 is passed, the constructor should throw an InvalidMonthNumberException. A constructor that accepts the name of the month, such as “January” or “February”, as an argument. It should set the monthNumber field to the correct corresponding value. If an invalid name is passed, the constructor should throw an InvalidMonthNameException. A setMonthNumber method that accepts an int argument, which is assigned to the monthNumber field. If a value less than 1 or greater than 12 is passed, throw an…arrow_forwardEmployee Management System Write a python class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Once you have written the class, write a PYTHON program that creates three Employee objects to hold the following data: Name ID Number Department Job Title Susan Meyers 47899 Accounting Vice President Mark Jones 39119 IT Programmer Joy Rogers 81774 Manufacturing Engineer The program should store this data in the three objects, then display the data for each employee on the screen.Using the Employee class, create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. The program should present a menu that lets the user perform the following actions: • Look up an employee in the dictionary• Add a new employee to the dictionary• Change an existing employee’s name, department, and job title in the dictionary• Delete an employee from the dictionary• Print all…arrow_forwardIn Python: Write a class named Pet, which should have the following data attributes: _ _name (for the name of a pet) _ _animal_type (for the type of animal that a pet is. Example values are 'Dog','Cat', and 'Bird') _ _age (for the pets age) The Pet class should have an _ _init_ _ method that creates these attributes. It should also have the following methods: set_nameThis method assigns a value to the _ _name field set_animal_typeThis method assigns a value to the _ _animal_type field set_ageThis method assignsa value to the _ _age field get_nameThis method assignsa value to the _ _name field get_animal_typeThis method assignsa value to the _ _animal_type field get_ageThis method assignsa value to the _ _age field Once you have written the class, write a program that creates an object of the class and prompts the user to enter the name, type and age of his or her pet. This data should be stored as the objects attributes. Use the objects accessor methods to retrieve the pets…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT