Java Assignment (Due at 6pm Today)
807607Oct 19 2006 — edited Oct 19 2006Can 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();
}
}