Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 14, Problem 2SA
Program Plan Intro
Data attribute:
- Data attributes are the properties of class that are stored in an object.
- The values of the data items which are stored inside an object are called data attributes.
- The data attributes can be accessed using dot operator.
- For example, a class “Car” has the properties such as car model, manufacture date, car name. These properties are the data attribute of “Car”.
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.
- Object’s variable is not directly accessible.
- Underscore helps in preventing the data being accessed directly.
The encapsulation rules in python can be summarized as
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. |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Exercise
docID document text
docID document text
1
hot chocolate cocoa beans
7
sweet sugar
2345
9
cocoa ghana africa
8
sugar cane brazil
beans harvest ghana
9
sweet sugar beet
cocoa butter
butter truffles
sweet chocolate
10
sweet cake icing
11
cake black forest
Clustering by k-means, with preprocessing tokenization, term weighting TFIDF.
Manhattan Distance. Number of cluster is 2. Centroid docID 2 and docID 9.
Change the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized.
The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position
public class Labyrinth { private final int size; private final Cell[][] grid;
public Labyrinth(int size) { this.size = size; this.grid = new Cell[size][size]; generateLabyrinth(); }
private void generateLabyrinth() { Random rand = new Random(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // Randomly create walls and paths grid[i][j] = new Cell(rand.nextBoolean()); } } // Ensure start and end are…
Change the following code so that it checks the following 3 conditions:
1. there is no space between each cells (imgs)
2. even if it is resized, the components wouldn't disappear
3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game.
Main():
Labyrinth labyrinth = new Labyrinth(10);
Player player = new Player(9, 0); Dragon dragon = new Dragon(9, 9);
JFrame frame = new JFrame("Labyrinth Game"); GameGUI gui = new GameGUI(labyrinth, player, dragon);
frame.add(gui); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; //labyrinth, player, dragon are just public classes
private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");…
Chapter 14 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Ch. 14.1 - What is an object?Ch. 14.1 - Prob. 14.2CPCh. 14.1 - Prob. 14.3CPCh. 14.1 - What are public methods? What are private methods?Ch. 14.2 - You hear someone make the following comment: A...Ch. 14.2 - In this chapter, we use the metaphor of a cookie...Ch. 14.2 - Prob. 14.7CPCh. 14.2 - Prob. 14.8CPCh. 14.2 - When a class variable is said to reference an...Ch. 14.2 - Prob. 14.10CP
Ch. 14.2 - Prob. 14.11CPCh. 14.2 - What is a constructor? When does a constructor...Ch. 14.2 - What is a default constructor?Ch. 14.3 - Prob. 14.14CPCh. 14.3 - Suppose a class has a field named description. The...Ch. 14.3 - Prob. 14.16CPCh. 14.4 - Prob. 14.17CPCh. 14.4 - What technique was described in this section for...Ch. 14.4 - What are classes responsibilities?Ch. 14.4 - Prob. 14.20CPCh. 14.5 - In this section, we discussed superclasses and...Ch. 14.5 - Prob. 14.22CPCh. 14.5 - What does a subclass inherit from its superclass?Ch. 14.5 - Look at the following pseudocode; which is the...Ch. 14.6 - Look at the following pseudocode class...Ch. 14 - Prob. 1MCCh. 14 - Prob. 2MCCh. 14 - A(n) ____ is a member of a class that holds data....Ch. 14 - The _________ specifies how a classs field or...Ch. 14 - A classs fields are commonly declared with the...Ch. 14 - Prob. 6MCCh. 14 - In many programming languages, the _____ key word...Ch. 14 - A(n) ____ method gets a value from a class's field...Ch. 14 - A(n) ____ method stores a value in a field or...Ch. 14 - A(n) ____ method is automatically called when an...Ch. 14 - A set of standard diagrams for graphically...Ch. 14 - When the value of an item is dependent on other...Ch. 14 - A classs responsibilities are _____. a. objects...Ch. 14 - In an inheritance relationship, the _____ is the...Ch. 14 - In an inheritance relationship, the _____ is the...Ch. 14 - The ___________ characteristic of object-oriented...Ch. 14 - The practice of procedural programming is centered...Ch. 14 - Object reusability has been a factor in the...Ch. 14 - It is a common practice in object-oriented...Ch. 14 - One way to find the classes needed for an...Ch. 14 - The superclass inherits fields and methods from...Ch. 14 - Polymorphism allows a class variable of the...Ch. 14 - Prob. 1SACh. 14 - Prob. 2SACh. 14 - What is the difference between a class and an...Ch. 14 - In many programming languages, what does the New...Ch. 14 - The following pseudocode statement calls an...Ch. 14 - Prob. 6SACh. 14 - What does a subclass inherit from its superclass?Ch. 14 - Look at the following pseudocode, which is the...Ch. 14 - Prob. 1AWCh. 14 - Look at this partial class definition, and then...Ch. 14 - Look at the following description of a problem...Ch. 14 - In pseudocode, write the first line of the...Ch. 14 - Look at the following pseudocode class...Ch. 14 - Pet Class Design a class named Pet, which should...Ch. 14 - Car Class Design a class named Car that has the...Ch. 14 - Personal Information Class Design a class that...Ch. 14 - Emp1oyee and ProductionWorker Classes Design an...Ch. 14 - Essay Class Design an Essay class that extends the...Ch. 14 - Patient Charges Design a class named Patient that...
Knowledge Booster
Similar questions
- Make the following game user friendly with GUI, with some simple graphics. The GUI should be in another seperate class, with some ImageIcon, and Game class should be added into the pane. The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return…arrow_forwardDiscuss the negative and positive impacts or information technology in the context of your society. Provide two references along with with your answerarrow_forwardA cylinder of diameter 10 cm rotates concentrically inside another hollow cylinder of inner diameter 10.1 cm. Both cylinders are 20 cm long and stand with their axis vertical. The annular space is filled with oil. If a torque of 100 kg cm is required to rotate the inner cylinder at 100 rpm, determine the viscosity of oil. Ans. μ= 29.82poisearrow_forward
- Make the following game user friendly with GUI, with some simple graphics The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return isWall; } public void setWall(boolean isWall) { this.isWall = isWall; } @Override public String toString() {…arrow_forwardPlease original work What are four of the goals of information lifecycle management think they are most important to data warehousing, Why do you feel this way, how dashboards can be used in the process, and provide a real life example for each. Please cite in text references and add weblinksarrow_forwardThe following is code for a disc golf program written in C++: // player.h #ifndef PLAYER_H #define PLAYER_H #include <string> #include <iostream> class Player { private: std::string courses[20]; // Array of course names int scores[20]; // Array of scores int gameCount; // Number of games played public: Player(); // Constructor void CheckGame(int playerId, const std::string& courseName, int gameScore); void ReportPlayer(int playerId) const; }; #endif // PLAYER_H // player.cpp #include "player.h" #include <iomanip> Player::Player() : gameCount(0) {} void Player::CheckGame(int playerId, const std::string& courseName, int gameScore) { for (int i = 0; i < gameCount; ++i) { if (courses[i] == courseName) { // If course has been played, then check for minimum score if (gameScore < scores[i]) { scores[i] = gameScore; // Update to new minimum…arrow_forward
- In this assignment, you will implement a multi-threaded program (using C/C++) that will check for Prime Numbers and Palindrome Numbers in a range of numbers. Palindrome numbers are numbers that their decimal representation can be read from left to right and from right to left (e.g. 12321, 5995, 1234321). The program will create T worker threads to check for prime and palindrome numbers in the given range (T will be passed to the program with the Linux command line). Each of the threads works on a part of the numbers within the range. Your program should have some global shared variables: • numOfPrimes: which will track the total number of prime numbers found by all threads. numOfPalindroms: which will track the total number of palindrome numbers found by all threads. numOfPalindromic Primes: which will count the numbers that are BOTH prime and palindrome found by all threads. TotalNums: which will count all the processed numbers in the range. In addition, you need to have arrays…arrow_forwardHow do you distinguish between hardware and a software problem? Discuss theprocedure for troubleshooting any hardware or software problem. give one reference with your answer.arrow_forwardYou are asked to explain what a computer virus is and if it can affect computer’shardware or software. How do you protect your computer against virus? give one reference with your answer.arrow_forward
- Distributed Systems: Consistency Models fer to page 45 for problems on data consistency. structions: Compare different consistency models (e.g., strong, eventual, causal) for distributed databases. Evaluate the trade-offs between availability and consistency in a given use case. Propose the most appropriate model for the scenario and explain your reasoning. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440AZF/view?usp=sharing]arrow_forwardOperating Systems: Deadlock Detection fer to page 25 for problems on deadlock concepts. structions: • Given a system resource allocation graph, determine if a deadlock exists. If a deadlock exists, identify the processes and resources involved. Suggest strategies to prevent or resolve the deadlock and explain their trade-offs. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440 AZF/view?usp=sharing]arrow_forwardArtificial Intelligence: Heuristic Evaluation fer to page 55 for problems on Al search algorithms. tructions: Given a search problem, propose and evaluate a heuristic function. Compare its performance to other heuristics based on search cost and solution quality. Justify why the chosen heuristic is admissible and/or consistent. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440 AZF/view?usp=sharing]arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
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