Java 新手问题求助
大神们帮忙看看:In the Pen class provide a method that takes a String and a Paper as arguments. It should append the
argument String to the argument Paper.这句话我不是很懂
In the Pen class provide a method that takes a String and a Paper as arguments. It should append the
argument String to the argument Paper.这里也想不出来
Define a class called Pen that contains a private int called ink. This represents the number of nonspace
characters that the Pen can write. Provide a constructor that initializes the ink to 100. Provide
a getter method to return the Pen's ink.
Define a class called Paper that contains a private String text. Provide a constructor that initializes
the text to an empty String. Provide a toString method that returns the text instance variable.
Give the Paper class a method called append that takes a String as an argument. It should add each
character in the argument to the end of the Paper's text. Because the text can be quite long, the
method should insert a newline character in appropriate places. Replace the first space character
following the 50th character on each line with a newline character. You may need to use if
statements and loops to do this.
In the Pen class provide a method that takes a String and a Paper as arguments. It should append the
argument String to the argument Paper. The Pen's ink should decrease by the number of non-space
characters that were written to the Paper. It should only append characters to the Paper until the
Pen's ink reaches zero.
Provide a main method to test these classes. Use Pens to write the first verse of The Raven, by Edgar
Allen Poe, to a Paper object.
"Once upon a midnight dreary, while I pondered, weak and weary, Over many a quaint and curious
volume of forgotten lore. While I nodded, nearly napping, suddenly there came a tapping, As of some
one gently rapping, rapping at my chamber door. "'Tis some visitor,” I muttered, "tapping at my
chamber door. Only this and nothing more."
Print out the Paper object to ensure that the whole poem was written to the Paper without error. It
may require multiple Pens to do this as they run out of ink. If your append and toString methods are
written correctly, when you print out the Paper you should see:
Once upon a midnight dreary, while I pondered, weak
and weary, Over many a quaint and curious volume of
forgotten lore. While I nodded, nearly napping, suddenly
there came a tapping, As of some one gently rapping,
rapping at my chamber door. "'Tis some visitor," I
muttered, "tapping at my chamber door. Only this and
nothing more."