In this project, you will explore an object-oriented alternative to the Hello, World program in Chapter 1.

Question:

In this project, you will explore an object-oriented alternative to the “Hello, World”

program in Chapter 1.

Begin with a simple Greeter class that has a single method, sayHello. That method should return a string, not print it. Create two objects of this class and invoke their sayHello methods. Of course, both objects return the same answer.

Enhance the Greeter class so that each object produces a customized greeting. For example, the object constructed as new Greeter("Dave") should say "Hello, Dave". (Use the concat method to combine strings to form a longer string, or peek ahead at Section 4.5 to see how you can use the + operator for the same pur pose.)

Add a method sayGoodbye to the Greeter class. Finally, add a method refuseHelp to the Greeter class. It should return a string such as

image text in transcribed

If you use BlueJ, place two Greeter objects on the workbench (one that greets the world and one that greets Dave) and invoke methods on them. Otherwise, write a tester program that constructs these objects, invokes methods, and prints the results.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question
Question Posted: