1. Engineering
  2. Computer Science
  3. problem create a message class that has the following instance...

Question: problem create a message class that has the following instance...

Question details

Problem: Create a Message class that has the following: Instance variables: 1) Instance variable message -- a String object consisting of some message. 2) Instance variable hidden -- a String object consisting of the same number of characters, but with all letters replaced by the "+" symbol. Spaces between words as well as punctuation should be preserved and not changed to the “+” symbol. Constructors: 1) A single constructor which takes in one argument (the String message), assigns it to the instance variable message, and automatically creates the instance variable hidden. For example, calling the constructor >>Message greeting = new Message(“Hello, world!”) would create a Message object greeting with Hello, world! stored in the message instance variable and +++++, +++++! stored in the hidden instance variable. This means that your constructor must create a new String, loop through the original message, and append either a “+” or spacing/punctuation to the new hidden string as appropriate. Methods: 1) A single method (other than main()) called showLetter. The showLetter() method takes in a letter (of class String) and updates the instance variable hidden so that the specified letter is shown in place of a “+” wherever it occurs in the instance variable message. For example, calling the method >>greeting.showLetter(“o”) would update hidden so that it is now ++++o, +o+++! and subsequently calling >>greeting.showLetter(“l”) would update hidden so that it is now ++llo, +o+l+!

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution