Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 10.4, Problem 2CP
Explanation of Solution
Encapsulation:
- • It combines the data and code into a single object.
- • It helps in restricting access to the methods.
- • This helps in preventing the data from being modified due to accident.
- • The object’s variable is not directly accessible.
- • Underscore helps in preventing the data from being accessed directly.
The encapsulation rules in Python can be summarized as follows:
Public method | It is accessible from anywhere. |
Public variables | It can be accessed from anywhere. |
Private method | It can be accessed only in their own class |
Private method | It is accessible only in their class or method. |
- • It protects the data from tampering. By declaring the data field as private, direct modifications of properties are prevented.
- • It makes the class easy to maintain and reduces the errors...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Transcribed Image Text
7-a) Danish works as a constructor. Like all constructors, he is also a beer fan. He likes beer so much that has K cups of beer daily. However, having more than K cups doesn't suit him, because the excess beer won't allow him to sleep at night. Danish's working day is divided into N periods. For every period, he knows how many kilobytes of weight he can lift. During each of the periods, Danish can either have or not to have one bottle of beer. If he is having a bottle of beer in some period, the amount of work in this period drops to zero. But he also gets a productivity boost, if he decides to skip beer during a period and the last bottle of beer, he had was no more than D periods ago, the amount of work during such a period is M times the usual.
Poker card in PythonLet the CarteBase class present itself in the context of this exercise. It encapsulates a game card characterized by numerical values for its face and its kind. The possible faces are integers from 1 to 13, with face 1 corresponding to the ace, and faces 11, 12 and 13 corresponding respectively to the jack, the queen and the king. The other faces are simply identified by their number from 2 to 10. The possible grades are integers from 1 to 4 corresponding respectively to the cards of spade, heart, tile and clover. Analyze this class to understand how it works.
You are asked to create a class called CarteDePoker that inherits CarteBase and defines or redefines the following methods:
force(self) which returns the strength of the card in the poker game. In Poker, cards have the strength of their digital face from 2 to 13, except for the ace which is stronger than the other cards. So we give it a strength of 14.__eq__(self, other) to define operator behavior…
These are about JS codes.
Q1:Make a new object called "person". Give the person object 2 properties; * name * age name should be a string array, the first position holds your first name, and second your last. age should be a number, date * output the entire object to the console.
/******************************************************************************* * Information: * * DOT NOTATION * * The object name (person) acts as the namespace — it must be entered first to access * anything inside the object. Next you write a dot, then the item you want to access * — this can be the name of a simple property, an item of an array property, or a call * to one of the object's methods. * * If you defined your object correctly in Q1, the following code should display your * name and age * ex: ********************************************************************************/ console.log(person.name); console.log(person.age);
Q2: Redfine (recreate) your person…
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
Similar questions
- Rewrite the client program to use the Baby class that you have done using ArrayList. You should also have the following function in this new client program: a) Enter details for each baby (name and age) and thus populate the Baby ArrayList b) Calculate and display the average age of all babies in the ArrayList c) Ask the user to enter the name of a baby, and then remove it from the ArrayList d) Allow the user to add new baby information in the ArrayList e) Output the details of each baby from the ArrayList (name and age) Compare this client program using the ArrayList with the client program you have done using array, comment on the differences between the two. Modify your client program in the last question, by adding a sort function such that when that option is selected, it sorts the ArrayList using the baby names in alphabetical order and output the details in the sorted ArrayList to a CSV (sortedbabylist.csv) file. public class Baby { private String name; private int age;…arrow_forwardRUBYarrow_forwardThe friend function is incompatible with the goal of encapsulation. Also, talk about the many applications for the friend function that you have.arrow_forward
- Hi can you help me to solve this question using java language , we have to use oop in this question also use string , we are not allow to use any thing inheritancearrow_forwardFind the body for: def contains_no_lowercase_vowels(phrase: str) -> bool: """Return True iff (if and only if) phrase does not contain any lowercase vowels. >>> contains_no_lowercase_vowels('syzygy') True >>> contains_no_lowercase_vowels('e') False >>> contains_no_lowercase_vowels('abc') False """arrow_forwardEvaluating Postfix Expression The Postfix notation is used to represent algebraic expressions. The expressions written in postfix form are evaluated faster compared to infix notation as parenthesis are not required in postfix. We have discussed infix to postfix conversion in the class. Write a Java program that will input a valid postfix expression. The expression may accept a whole number or a real number. Every operand and operator should be separated by a space. Make sure to trap possible errors.Sample Output (Must be implement in GUI)arrow_forward
- def winning_card(cards, trump=None): Playing cards are again represented as tuples of (rank,suit) as in the cardproblems.pylecture example program. In trick taking games such as whist or bridge, four players each play one card from their hand to the trick, committing to their play in clockwise order starting from the player who plays first into the trick. The winner of the trick is determined by the following rules:1. If one or more cards of the trump suit have been played to the trick, the trick is won by the highest ranking trump card, regardless of the other cards played.2. If no trump cards have been played to the trick, the trick is won by the highest card of the suit of the first card played to the trick. Cards of any other suits, regardless of their rank, are powerless to win that trick.3. Ace is the highest card in each suit.Note that the order in which the cards are played to the trick greatly affects the outcome of that trick, since the first card played in the trick…arrow_forwardTranscribed Image Text JAVA Programming Problem: In the game of "Assassin's Creed", you control a ship with a cannon which is attacking a large enemy Assassin's Creed, armed with many guns. Your goal is to destroy as many of the guns as possible. The battle field is a 2D Cartesian grid, where your cannon is located at the origin. The enemy Assassin's Creed is a horizontal line segment located from the coordinates (X1, Y) to (X2, Y). There are exactly (X2 - X1 + 1) guns on the ship, located at the integer points (X1, Y), (X1+1, Y), ..., (X2, Y). However, the problem is, you cannot always fire at a gun. There are supernatural rocks located at all points of the battlefield whose X and Y coordinates are both integers. In order to fire successfully at an enemy's gun, the line connecting your cannon and that gun must not go through any rocks. Develop a JAVA code to output the number of the enemy battleship's guns that your cannon can destroy. Test Case Result 1 2 2 -2arrow_forwardComputer Science Bob takes medication three times a day. In the morning at 8:00, in the afternoon at 13:00, and in the evening at 19:00. Create an enum type that maps the times Bob takes his medication.arrow_forward
- o Implement a class for computing the area of circle, rectangle, square Use overriding functions for computing area Use overriding functions for different data types (int, double)arrow_forwardCreate a calculator for the complex number by creating a class of complex number with overloading all operators in it.(Operators: ++,-,+/,>>, <<).arrow_forwardfngdndndnn n dnnndnfnfnarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher: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