Refining a Problem’s Solution

In this lesson, we will complete our discussion of the café sign problem.

We'll cover the following

Let’s enhance the class CafeSign that we developed in the previous lesson using the ideas we have presented so far.

One solution

Our first enhancement to CafeSign adds the name of the café as a private data field and defines a constructor to initialize it. The class will have only one public method, getMessage that returns the sign’s contents as a string. It calls several private methods, including the method getMealServedMessage. This method has logic much like that of getMealServed in our early version of the class, as given in the previous lesson.

Imagine that we temporarily omit the opening time from the message “See you at . . . ” in the sign’s third line, as we suggested in the previous lesson. Since we plan to add this information to the message as soon as we get the rest of the class written and tested, we will have the method getMealServedMessage call another private method getNextMealTime, that we write as a stub. We should be able to get this much of the class written rather quickly, in light of our previous testing. The code given below shows our class so far.

Get hands-on with 1200+ tech skills courses.