Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a public class StringAppender, which stores a single String and allows Strings to be appended to it. Here's how it works. Provide a
Create a public class StringAppender, which stores a single String and allows Strings to be appended to it. Here's how it works. Provide a public constructor taking a single String that sets the initial state of the StringAppender. assert that the String passed to the constructor is not null. The saved String should be private, so do not provide a setter or getter for it. Also provide a method append that accepts a single String, appends it to the saved String, and returns the new String, append should also assert that the passed String is not null. When complete, here is how your class should work: 1 StringAppender appender = new StringAppender ("pets"); 2 System.out.println(appender.append("gracie")); // prints "petsgracie" 3 System.out.println(appender.append("xyz")); // prints "petsgraciexyz" 4 System.out.println(appender.append(null)); // fails. WORKING PREVIOUS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started