Exercise 7: Modify your printDetails method to include printing the reference number. However, the method should print the reference number only if it has been set-that is, if the refNumber string has a non-zero length. If it has not been set, then print the string "ZZz" instead. Hint: Use a conditional statement whose test calls the length method on the refNumber string.

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



1.
Exercise 7: Modify your printDetails method to include printing the
reference number. However, the method should print the reference number
only if it has been set-that is, if the refNumber string has a non-zero
length. If it has not been set, then print the string "ZZz" instead. Hint:
Use a conditional statement whose test calls the length method on the
refNumber string.
Exercise 8: Modify your setRefNumber mutator so that it sets the refNumber
field only if the parameter is a string of at least three characters. If
it is less than three, then print an error message and leave the field
unchanged.
Exercise 9: Add a further integer field, borrowed, to the Book class. This
keeps a count of the number of times a book has been borrowed. Add a mutator,
borrow, to the class. This should update the field by 1 each time it is
called. Include an accessor, getBorrowed, that returns the value of this
new field as its result. Modify printDetails so that it includes the value
of this field with an explanatory piece of text.
Exercise 10: Add a further boolean field, courseText, to the Book class.
This records whether or not a book is being used as a text book on a course.
The field should be set through a parameter to the constructor, and the
field is immutable. Provide an accessor method for it called isCourseText.
Transcribed Image Text:1. Exercise 7: Modify your printDetails method to include printing the reference number. However, the method should print the reference number only if it has been set-that is, if the refNumber string has a non-zero length. If it has not been set, then print the string "ZZz" instead. Hint: Use a conditional statement whose test calls the length method on the refNumber string. Exercise 8: Modify your setRefNumber mutator so that it sets the refNumber field only if the parameter is a string of at least three characters. If it is less than three, then print an error message and leave the field unchanged. Exercise 9: Add a further integer field, borrowed, to the Book class. This keeps a count of the number of times a book has been borrowed. Add a mutator, borrow, to the class. This should update the field by 1 each time it is called. Include an accessor, getBorrowed, that returns the value of this new field as its result. Modify printDetails so that it includes the value of this field with an explanatory piece of text. Exercise 10: Add a further boolean field, courseText, to the Book class. This records whether or not a book is being used as a text book on a course. The field should be set through a parameter to the constructor, and the field is immutable. Provide an accessor method for it called isCourseText.
Exercise 1: Add two accessor methods to the class-getAuthor and
getTitle- that return the author and title fields as their respective
results. Test your class by creating some instances and calling the
methods.
Exercise 2: Add two methods, printAuthor and printTitle, to the outline
Book class. These should print the author and title fields, respectively,
to the terminal window.
Exercise 3: Add a field, pages, to the Book class to store the number
of pages. This should be of type int, and its initial value should be passed
to the single constructor, along with the author and title strings.
Include an appropriate getPages accessor method for this field.
Exercise 4: Are the Book objects you have implemented immutable? Justify
your answer.
Exercise 5: Add a method, printDetails, to the Book class. This should
print details of the author, title, and pages to the terminal window. It
is your choice how the details are formatted. For instance, all three items
could be printed on a single line, or each could be printed on a separate
line. You might also choose to include some explanatory text to help a
user work out which is the author and which is the title, for example Title:
Robinson Crusoe, Author: Daniel Defoe, Pages: 232
Exercise 6: Add a further field, refNumber, to the Book class. This field
can store a reference number for a library, for example. It should be of
type String and initialized to the zero length string ("") in the
constructor, as its initial value is not passed in a parameter to the
constructor. Instead, define a mutator for it with the following header:
public void setRefNumber (String ref) The body of this method should assign
Transcribed Image Text:Exercise 1: Add two accessor methods to the class-getAuthor and getTitle- that return the author and title fields as their respective results. Test your class by creating some instances and calling the methods. Exercise 2: Add two methods, printAuthor and printTitle, to the outline Book class. These should print the author and title fields, respectively, to the terminal window. Exercise 3: Add a field, pages, to the Book class to store the number of pages. This should be of type int, and its initial value should be passed to the single constructor, along with the author and title strings. Include an appropriate getPages accessor method for this field. Exercise 4: Are the Book objects you have implemented immutable? Justify your answer. Exercise 5: Add a method, printDetails, to the Book class. This should print details of the author, title, and pages to the terminal window. It is your choice how the details are formatted. For instance, all three items could be printed on a single line, or each could be printed on a separate line. You might also choose to include some explanatory text to help a user work out which is the author and which is the title, for example Title: Robinson Crusoe, Author: Daniel Defoe, Pages: 232 Exercise 6: Add a further field, refNumber, to the Book class. This field can store a reference number for a library, for example. It should be of type String and initialized to the zero length string ("") in the constructor, as its initial value is not passed in a parameter to the constructor. Instead, define a mutator for it with the following header: public void setRefNumber (String ref) The body of this method should assign
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 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