Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To introduce another few methods and practice with them, let's write one more method. Sometimes, when printing an inventory, we might have long titles (

To introduce another few
methods and practice with them, let's write one more method. Sometimes, when printing an inventory, we
might have long titles (like the full title of "Make It Stick" ) that don't fit in a column width-wise. A common trick is to truncate the string
down to a certain length, and replace the end with ""..". If the string is below the given length, we leave it alone. So let's
write truncateTitle(), which will take in a length to cut the title down to, and return the truncated title.
class Book {
??**
@param length The number of characters to appear before "..."
@return A new string containing length characters followed by "..." if the
string was too long, or the original string otherwise
*/
String truncateTitle(int length){
}
}
class ExamplesBook {
Book schemer = new Book("The Little Schemer", "Daniel P. Friedman", 40);
Book stick = new Book("Make It Stick: The Science of Successful Learning", "Peter C. Brown", 13);
String truncate1= this.stick.truncateTitle(15);
String truncate 2= this.schemer.truncateTitle(20);
String truncate 3= this.schemer. truncateTitle();
}
Do Now! Determine the expected output for the following calls to
Fill in the blanks
String truncate1= this.stick.truncateTitle(15); // should be
String truncate2= this.schemer.truncateTitle(20); //should be
String truncate 3= this.schemer.truncateTitle(); //should be
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Are my points each supported by at least two subpoints?

Answered: 1 week ago