Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 10, Problem 2AW
Program Plan Intro
- • Create a class named “Book”.
Part a: Defining “__init__” method
- • Now define the “__init__()” method for the class. Inside the method,
- ○ Assign the attribute for “book_title”.
- ○ Assign the attribute for “author_name”.
- ○ Assign the attribute for “publisher_name”.
Part b: Creating accessor and mutator methods:
- • Define an accessor method named “set_book_title()”
- ○ Now assign the attribute “book_title”.
- • Define an accessor method named “set_author_name()”
- ○ Now assign the attribute “author_name”.
- • Define an accessor method named “set_publisher_name ()”
- ○ Now assign the attribute “publisher_name”.
- • Define the mutator method named “get_book_title()”
- ○ Return the value for “book_title”.
- • Define the mutator method named “get_author_name ()”
- ○ Return the value for “author_name”.
- • Define the mutator method named “get_publisher_name ()”
- ○ Return the value for “publisher_name”.
Part c: Defining the “__str__” method to return a string:
- • Now define the “__str__()” method.
- ○ Return the values for string variables.
- • Create an object “object1” for the class “BOOK”.
- • Now print the values using the “print” statement.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Create a class that represents an employee. This class will have three constructors to initialize variables. If the constructor doesn't provide a parameter for a field, make it either "(not set)" or "0" as appropriate.
Name:
Employee
Fields:
- name : String
- idNumber : int
- department : String
- position : String
Methods:
+ Employee()
+ Employee(name : String, idNumber : int)
+ Employee(name : String, idNumber : int, department : String, position : String)
+ getName() : String
+ getDepartment() : String
+ getPosition() : String
+ getIdNumber() : intEmployeeDemo.java Code
public class EmployeeDemo{public static void printInfo(Employee e){System.out.println(e.getName() + ", " + e.getIdNumber() + ", " + e.getDepartment() + ", " + e.getPosition());}public static void main(String[] args){Employee e1 = new Employee();Employee e2 = new Employee("Bill Gates", 1975);Employee e3 = new Employee("Steve Jobs", 1976, "Design",…
Create a class that represents an employee. This class will have three constructors to initialize variables. If the constructor doesn't provide a parameter for a field, make it either "(not set)" or "0" as appropriate.
Name: Employee
Fields: - name : String - idNumber : int - department : String - position : String
Methods: + Employee() + Employee(name : String, idNumber : int) + Employee(name : String, idNumber : int, department : String, position : String) + getName() : String + getDepartment() : String + getPosition() : String + getIdNumber() : int
use test case as result
a) Create an enumeration named Departments that contain four set of values FINANCE, HR, IT, and MARKETING.b) Create a class named PersonDetails that contains fields for a person’s first name (String), last name (String), and address (String). The class have- A constructor that accepts parameters for each field.- Get methods for each field.c) Create a class named Employee that contains fields for an employee ID (int), Social Security number (String), personal information (Person object), department (Departments type), and annual salary (double). The class have- A constructor that requires values for each data field.- Get methods for each of the data fields.- Set methods for each of the data fields.d) Create an application/class named EmployeeSort that allows a user to enter values for an array of 5 Employee objects (create an array of Employee type that will save 5 employee objects). Prompt a user for the data needed to create an employee object. Continue to prompt the user for Social…
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...
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
- a) Create an enumeration named Departments that contain four set of values FINANCE, HR, IT, and MARKETING.b) Create a class named PersonDetails that contains fields for a person’s first name (String), last name (String), and address (String). The class have- A constructor that accepts parameters for each field.- Get methods for each field.c) Create a class named Employee that contains fields for an employee ID (int), Social Security number (String), personal information (Person object), department (Departments type), and annual salary (double). The class have- A constructor that requires values for each data field.- Get methods for each of the data fields.- Set methods for each of the data fields.d) Create an application/class named EmployeeSort that allows a user to enter values for an array of 5 Employee objects (create an array of Employee type that will save 5 employee objects). Prompt a user for the data needed to create an employee object. Continue to prompt the user for Social…arrow_forwardCreate a class that represents an employee. This class will have three constructors to initialize variables. If the constructor doesn't provide a parameter for a field , make it either "(not set)" or "0" as appropriate. Name: Employee Fields : - name : String - idNumber : Int - department : String - position : String Methods: + Employee() + Employee(name : String, idNumber : int) + Employee(name : String, idNumber : int, department : String, position : String) + getName() : String + getDepartment() : String + getPosition() : String + getIdNumber() : int Write in java and use test case #1 as an example.arrow_forwarda) Create an enumeration named Departments that contain four sets of values FINANCE, HR, IT, and MARKETING.b) Create a class named PersonDetails that contains fields for a person’s first name (String), last name (String), and address (String). The class haveA constructor that accepts parameters for each field and Get methods for each field.c) Create a class named Employee that contains fields for an employee ID (int), Social Security number (String), personal information (Person object), department (Departments type), and annual salary (double). The class haveA constructor that requires values for each data field.Get methods for each of the data fields.Set methods for each of the data fields.d) Create an application/class named EmployeeSort that allows a user to enter values for an array of 5 Employee objects (create an array of Employee type that will save 5 employee objects). Prompt a user for the data needed to create an employee object. Continue to 2prompt the user for Social…arrow_forward
- You are in process of writing a class definition for the class Book. It has three data attributes: book_title, book_author, and book_publisher. The data attributes should be private. In Python, write a setter/mutator method and a getter/accessor method for book_title(only) that will be part of your class definition. Note: You do not need to write the entire class definition. Just the two methods mentioned.arrow_forwardWrite a class named RetailItem that holds data about an itemin a retail store. The class should store the following data inattributes: item description, brand, units in inventory, and price.2. Make sure you have getter and setter methods (accessor andmutator methods) for the class created.3. The class is to have a method that properly displays object datawhen/if object is passed to the print function. Hint:__str__4. Create a program that creates three RetailItem objects andstores their information.5. The information for the 3 objects you need to create is listedbelow:Description Brand Units in Inventory Unit PriceItem #1 Jacket REI 12 130.95Item #2 Designer Jeans Levi 40 34.95Item #3 Shirt Nike 20 24.956. After storing the items as objects, calculate the total price for eachitem (units x unit price) then display the items as shown in thetable above but with an additional column titled “Total Price” thatdisplays the total price the program has calculated for each item.Image below shows…arrow_forward1.Write a class named Car that has the following data attributes:(a.) __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 andmake as arguments.These values should be assigned to the object’s __year_model and __make dataattributes.It should also assign 0 to the __speed data attribute.The class should also have the following methods:(b). Accelerate: The accelerate method should add 5 to the speed data attributeeach time it is called.Brake: The brake method should subtract 5 from the speed data attribute eachtime it is called.get_speed: The get_speed method should return the current speedarrow_forward
- Write a class named Car that has the following data attributes in pyton:a. __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:b. 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 speedarrow_forwardWrite a class to maintain data about a single pizza. It should maintain information about its topping, size, and price. The class should have appropriate get and set methods. Once you have the class written, it is time to write the program that will use the class. It needs to create 2 Pizza objects, set the data, and then print the data about each pizza. Use the following values when creating your pizzas: Pizza 1 Topping: Extra Cheese Pizza 1 Diameter: 14 Pizza 1 Price: 15.99 Pizza 2 Topping: Pepperoni Pizza 2 Diameter: 12 Pizza 2 Price: 13.49 Note that this program has no user input (no cin statements) Sample Run #1 (bold, underlined text is what the user types): Pizza 1 is a 14 inch pizza with Extra CheeseIt will cost $15.99Pizza 2 is a 12 inch pizza with PepperoniIt will cost $13.49arrow_forwarda. Write a class named Student has the following data fields and methods: private int Id private double GPA Constructor to create a Student object with specified name, address, Id and GPA. Accessors and mutators methods for Id and GPA data fields (get and set). A method toString () that returns Id, name and address and GPA. b. Write a test program that creates a Student object with Id:123 Name: Ahmed address: Muscat grade: 2.55 & then call toString () method to display Id, name and address and GPA.arrow_forward
- Write a program named DemoJobs for Harolds Home Services. The program should instantiate several Job objects and demonstrate their methods. The Job class contains four data fields—description (for example, wash windows), time in hours to complete (for example, 3.5), per-hour rate charged (for example, $25.00), and total fee (hourly rate times hours). Include properties to get and set each field except the total fee—that field will be read-only, and its value is calculated each time either the hourly fee or the number of hours is set. Overload the + operator so that two Jobs can be added. The sum of two Jobs is a new Job containing the descriptions of both original Jobs (joined by and), the sum of the time in hours for the original Jobs, and the average of the hourly rate for the original Jobs. Harold has realized that his method for computing the fee for combined jobs is not fair. For example, consider the following: His fee for painting a house is $100 per hour. If a job takes 10 hours, he earns $1000. His fee for dog walking is $10 per hour. If a job takes 1 hour, he earns $10. If he combines the two jobs and works a total of 11 hours, he earns only the average rate of $55 per hour, or $605. Devise an improved, weighted method for calculating Harolds fees for combined Jobs and include it in the overloaded operator+() method. Write a program named DemoJobs2 that demonstrates all the methods in the class work correctly.arrow_forwardIn previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing Dancing, Musical instrument, and Other. The class contains an auto-implemented property that holds a contestants name. The class contains fields for a talent code and description. The set accessor for the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. The talent description is a read-only property that is assigned a value when the code is set. Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this years competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. The program prompts the user for names and talent codes for each contestant entered. Along with the prompt for a talent code, display a list of the valid categories. After data entry is complete, the program displays the valid talent categories and then continuously prompts the user for talent codes and displays the names of all contestants in the category. Appropriate messages are displayed if the entered code is not a character or a valid code.arrow_forwardMy professor has given me additional information for this question: Create a class named CollegeCourse that includes data fields that hold thedepartment (for example, ENG), the course number (for example, 101), thecredits (for example, 3), and the fee for the course (for example, $360). All of thefields are required as arguments to the constructor, except for the fee, which iscalculated at $120 per credit hour. Include a display() method that displaysthe course data. Create a subclass named LabCourse that adds $50 to the coursefee. Override the parent class display() method to indicate that the course isa lab course and to display all the data. Write an application named UseCoursethat prompts the user for course information. If the user enters a class in any ofthe following departments, create a LabCourse: BIO, CHM, CIS, or PHY. If theuser enters any other department, create a CollegeCourse that does not includethe lab fee. Then display the course data. Save the files as…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,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT