have the same (x, y) Section 8.4: Encapsulation 22. What is abstraction? How do objects provide abstraction? 23. What is the difference between the public and private keywords? What items should be declared private? 24. When fields are made private, client programs cannot see them directly. How do you allow classes access to read these fields' values, without letting the client break the object's encapsulation? 25. Add methods named setx and sety to the Point class that allow clients to change a Point object's x-and y-coordinates, respectively. 26. (You must complete Self-Check Problem 7 before answering this question.) Encapsulate the Name class. Make its fields private and add appropriate accessor methods to the class. 27. (You must complete Self-Check Problem 26 before answering this question.) Add methods called setFirstName, setMiddleInitial, and setLastName to your Name class. Give the param eters the same names as your fields, and use the this keyword in your solution. 28. How does encapsulation allow you to change the internal implementation of a class?

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Number 25
580
Chapter 8 Classes
Section 8.3: Object Initialization: Constructors
17. What is a constructor? How is a constructor different from other methods?
18. What are two major problems with the following constructor?
public void Pointfint initialx, int initialy) (
int
initial;
int y initial;
)
19. (You must complete Self-Check Problem 7 before answering this question.)
Add a constructor to the same class that accepts a first name, middle initial, and last name as parameters and
initializes the same object's state with those values.
21. Add a constructor to the Point class that accepts another Point as a parameter and initializes this new Point to
20. What is the meaning of the keyword this? Describe three ways that the keyword can be used.
have the same (x, y) values. Use the keyword this in your solution.
Section 8.4: Encapsulation
22. What is abstraction? How do objects provide abstraction?
23. What is the difference between the public and private keywords? What items should be declared private?
24. When fields are made private, client programs cannot see them directly. How do you allow classes access to read these
fields' values, without letting the client break the object's encapsulation?
25. Add methods named setx and sety to the point class that allow clients to change a Point object's x-and
y-coordinates, respectively.
26. (You must complete Self-Check Problem 7 before answering this question.)
Encapsulate the Name class. Make its fields private and add appropriate accessor methods to the class.
27. (You must complete Self-Check Problem 26 before answering this question.)
Add methods called setFirst Name, setMiddleInitial, and setLastName to your Name class. Give the para
eters the same names as your fields, and use the this keyword in your solution.
28. How does encapsulation allow you to change the internal implementation of a class?
Section 8.5: Case Study: Designing a Stock Class
29. What is cohesion? How can you tell whether a class is cohesive?
30. Why didn't we choose to put the console I/O code into the Stock class?
31. Add accessor methods to the stock class to return the stock's symbol, total shares, and total cost.
Exercises
1. Add the following accessor method to the Point class:
public int quadrant ()
Returns which quadrant of the x/y plane the current Point object falls in. Quadrant 1 contains all points whose x
and y values are both positive. Quadrant 2 contains all points with negative x but positive y. Quadrant 3 contains a
Transcribed Image Text:580 Chapter 8 Classes Section 8.3: Object Initialization: Constructors 17. What is a constructor? How is a constructor different from other methods? 18. What are two major problems with the following constructor? public void Pointfint initialx, int initialy) ( int initial; int y initial; ) 19. (You must complete Self-Check Problem 7 before answering this question.) Add a constructor to the same class that accepts a first name, middle initial, and last name as parameters and initializes the same object's state with those values. 21. Add a constructor to the Point class that accepts another Point as a parameter and initializes this new Point to 20. What is the meaning of the keyword this? Describe three ways that the keyword can be used. have the same (x, y) values. Use the keyword this in your solution. Section 8.4: Encapsulation 22. What is abstraction? How do objects provide abstraction? 23. What is the difference between the public and private keywords? What items should be declared private? 24. When fields are made private, client programs cannot see them directly. How do you allow classes access to read these fields' values, without letting the client break the object's encapsulation? 25. Add methods named setx and sety to the point class that allow clients to change a Point object's x-and y-coordinates, respectively. 26. (You must complete Self-Check Problem 7 before answering this question.) Encapsulate the Name class. Make its fields private and add appropriate accessor methods to the class. 27. (You must complete Self-Check Problem 26 before answering this question.) Add methods called setFirst Name, setMiddleInitial, and setLastName to your Name class. Give the para eters the same names as your fields, and use the this keyword in your solution. 28. How does encapsulation allow you to change the internal implementation of a class? Section 8.5: Case Study: Designing a Stock Class 29. What is cohesion? How can you tell whether a class is cohesive? 30. Why didn't we choose to put the console I/O code into the Stock class? 31. Add accessor methods to the stock class to return the stock's symbol, total shares, and total cost. Exercises 1. Add the following accessor method to the Point class: public int quadrant () Returns which quadrant of the x/y plane the current Point object falls in. Quadrant 1 contains all points whose x and y values are both positive. Quadrant 2 contains all points with negative x but positive y. Quadrant 3 contains a
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY