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

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

"I am sorry, Dave. I am afraid I can't do that."

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.

"I am sorry, Dave. I am afraid I can't do that."

Step by Step Solution

3.50 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the project description you provided you will need to create a Greeter class in an objectoriented programming language like Java Heres a step... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!