Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Assignment (Due at 6pm Today)

807607Oct 19 2006 — edited Oct 19 2006
Can someone please help me with this assignment today. It's due at 6pm. The professor really didn't explain the chapter but gave us the assignment. So i will really appreciate if someone can help me with this.. Thank you....


Modify the program in Chapter 30 so that a HelloObject object writes out the greeting as many times as there are characters in the greeting. The HelloObject class will have a constructor that allows the main() method to initialize objects to different greetings.

C:\>java Hello
Hello
Hello
Hello
Hello
Hello



Here is the sample program......

class HelloObject
{
String greeting;

HelloObject( String st )
{
greeting = st;
}

void speak()
{
System.out.println( greeting );
}
}

class HelloTester
{
public static void main ( String[] args )
{
HelloObject object1 = new HelloObject("Mercury");
HelloObject object2 = new HelloObject("Venus");
HelloObject object3 = new HelloObject("Earth");
HelloObject object4 = new HelloObject("Mars");

object1.speak();
object2.speak();
object3.speak();
object4.speak();
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 16 2006
Added on Oct 19 2006
10 comments
345 views