Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Videos

Textbook Question
100%
Chapter 10, Problem 1PE

Pet Class

The Pet class

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 pet’s age)

The Pet class should have an _ _init_ _ method that creates these attributes. It should also have the following methods:

■ set_name

This method assigns a value to the _ _name field.

■ set_animal_type

This method assigns a value to the _ _animal_type field.

■ set_age

This method assigns a value to the _ _age field.

■ get_name

This method returns the value of the _ _name field.

■ get_animal_type

This method returns the value of the _ _animal_type field.

■ get_age

This method returns the value of 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 object’s attributes. Use the object's accessor methods to retrieve the pet’s name, type, and age and display this data on the screen.

Blurred answer
03:32
Students have asked these similar questions
(Invoice Class) Create a class called Invoice that a hardware store might use to representan invoice for an item sold at the store. An Invoice should include four data members—a part number (type string), a part description (type string), a quantity of the item being purchased (typeint) and a price per item (type int). Your class should have a constructor that initializes the fourdata members. A constructor that receives multiple arguments is defined with the form:ClassName( TypeName1 parameterName1, TypeName2 parameterName2, ... )Provide a set and a get function for each data member. In addition, provide a member functionnamed getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by theprice per item), then returns the amount as an int value. If the quantity is not positive, it should beset to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates class Invoice’s capabilities
Problem: Employee and ProductionWorker Classes Write a python class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: • Shift number (an integer, such as 1, 2, or 3)• Hourly pay rateThe workday is divided into two shifts: day and night. The shift attribute will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write the appropriate accessor and mutator methods for this class. Once you have written the class, write a program that creates an object of the ProductionWorker class, and prompts the user to enter data for each of the object’s data attributes. Store the data in the object, then use the object’s accessor methods to retrieve it and display it on the screen   Note: The program should be written in python.     Sample Input/Output: Enter the name: Ahmed Al-AliEnter the ID number: 12345Enter the department:…
C++ Code: Goal: Write a Class to represent Fractions Write a Fraction class whose objects will represent fractions. For example, a fraction of 3/7 will be represented by a Fraction object whose numerator will be set to 3 and denominator will be set to 7. Implementation Note: For this checkpoint do not reduce fractions (i.e. 15/18 should NOT be reduced to 5/6), do not use "const" (since we haven't discussed in class yet)  Attributes: Your class should have exactly two private data members, one to represent the numerator of the Fraction being represented, and one to represent the denominator of the Fraction being represented. (What should be the data type of these member variables?) Member functions: A default constructor that sets the fraction to 0 (what should be the numerator and denominator for such a fraction?). A parametrized constructor takes two integer arguments, a numerator and a denominator, and assigns the attributes accordingly. Arithmetic operations that add,…

Chapter 10 Solutions

Starting Out with Python (4th Edition)

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...
Knowledge Booster
Computer Science
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
  • RetailItem 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.95
    A(n) is a unique form of class member that enables an object to store and retrieve data.
    C++ Pet Class You are going to organize and show information about pets in a Pet Store using a Pet class. The Pet class You need to make a Pet class that holds the following information as private data members: the name of the pet (e.g. "Spot", "Fluffy", or any word a user enters) the type of pet (e.g. dog, cat, snake, hamster, or any word a user enters) level of hungriness of the pet (2 means hungry, 1 means content, 0 means full) Your class also needs to have the following functions: a default constructor that sets the pet to be a dog named Buddy, with level of hungriness being “content” a parameterized constructor to allow having any type of pet the order of the parameters is: name of the pet, type of pet, hungriness level a PrintInfo function that prints the info for the pet according to the sample output below a TimePasses function that increases the hungry level of the pet by one (unless its hungry level is already 2, meaning hungry). a FeedPet function that changes the…
  • C++ Pet Class You are going to organize and show information about pets in a Pet Store using a Pet class. The Pet class You need to make a Pet class that holds the following information as private data members: the name of the pet (e.g. "Spot", "Fluffy", or any word a user enters) the type of pet (e.g. dog, cat, snake, hamster, or any word a user enters) level of hungriness of the pet (2 means hungry, 1 means content, 0 means full) Your class also needs to have the following functions: a default constructor that sets the pet to be a dog named Buddy, with level of hungriness being “content” a parameterized constructor to allow having any type of pet the order of the parameters is: name of the pet, type of pet, hungriness level a PrintInfo function that prints the info for the pet according to the sample output below a TimePasses function that increases the hungry level of the pet by one (unless its hungry level is already 2, meaning hungry). a FeedPet function that changes the…
    Complete the code for the Student class method called void loadStudent(...) that receives a single string parameter. This string parameter will contain student details in the following format: ’Name’,’Surname’,’Email’,’Age’,’Student Number’ Write the code to separate the string and assign the correct values to the Student class members.   Create an overloaded > (greater than) operator in the Student class. The operator will compare the age of two student objects and return the object with the greater age. In main.cpp create a non member function named isFemale. This function will receive as parameter a pointer to a student object. If the last two numbers of the student number is valid numbers (Must be between 0 and 9) the function will return true. Otherwise the function will return false. Overload the default constructor for Student to receive a single string parameter. This string parameter will contain student details in the following format:…
    Account Class) Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type intto represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. Theconstructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display anerror message indicating that the initial balance was invalid. Provide three member functions. Member function credit should add anamount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amountdoes not exceed the Account’s balance. If it does, the balance should be left unchanged and the function should print a messageindicating "Debit amount exceeded account balance." Member function getBalance should return the current balance. Create a programthat creates two Account objects and tests the member functions…
  • User-defined Class: You will design and implement your own data class. The class will store data that has been read as user input from the keyboard (see Getting Input below), and provide necessary operations. As the data stored relates to monetary change, the class should be named MoneyChange. The class requires at least 2 instance variables for the name of a person and the coin change amount to be given to that person. You may also wish to use 6 instance variables to represent amounts for each of the 6 coin denominations (see Client Class below). There should be no need for more than these instance variables. However, if you wish to use more instance variables, you must provide a legitimate justification for their usage in the internal and external documentation.Your class will need to have at least a default constructor, and a constructor with two parameters:one parameter being a name and the other a coin amount. Your class should also provide appropriate get and set methods for…
    Circle Class (Easy)   Write a Circle class that has the following member variables: radius : a  double    The class should have the following member functions:    Default Constructor:  default constructor that sets radius to 0.0.  Constructor: accepts the radius of the circle as an argument.  setRadius: an mutator function for the radius variable. getRadius: an accessor function for the radius variable. getArea: returns the area of the circle, which is calculated as area = pi * radius * radius    getCircumference: returns the circumference of the circle, which is calculated as circumference = 2 * pi * radius         Step1:  Create a declaration of the class.   Step2: Write a program that demonstrates the Circle class by asking the user for the circle’s radius, creating              Circle objects, and then reporting the circle’s area, and circumference.                You should create at least two circle objects, one sets the radius to 0.0 and one accepts the radius as an…
    py You want to initialize parts of a class definition once at the time a class is defined, notwhen instances are created.
  • (Rectangle Class) Create a class Rectangle with attributes length and width, each of whichdefaults to 1. Provide member functions that calculate the perimeter and the area of the rectangle.Also, provide set and get functions for the length and width attributes. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.
    (Date Class) Create a class called Date that includes three pieces of information as datamembers—a month (type int), a day (type int) and a year (type int). Your class should have a constructor with three parameters that uses the parameters to initialize the three data members. For thepurpose of this exercise, assume that the values provided for the year and day are correct, but ensurethat the month value is in the range 1–12; if it isn’t, set the month to 1. Provide a set and a get function for each data member. Provide a member function displayDate that displays the month, dayand year separated by forward slashes (/). Write a test program that demonstrates class Date’s capabilities.
    Class and Data members: Create a class called Temperature that stores temperature readings (integers) in a vector (do not use an array).  The class should have data members that store the month name and year of when the temperature readings were collected.   Constructor(s): The class should have a 2-argument constructor that receives the month name and year as parameters and sets the appropriate data members to these values.   Member Functions: The class should have functions as follows:   Member functions to set and get the month and year variables.   A member function that adds a single temperature to the vector. Both negative and positive temperatures are allowed.  Call this function AddTemperature.   A member function to sort the vector in ascending order.   Feel free to use the sort function that is available in the algorithm library for sorting vectors. Or, if you would prefer to write your own sort code, you may find this site to be helpful:…
    • SEE MORE QUESTIONS
    Recommended textbooks for you
  • Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
  • C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education
  • Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education
    C++ Data Members; Author: CppNuts;https://www.youtube.com/watch?v=StlsYRNnWaE;License: Standard YouTube License, CC-BY