Java 新手问题求助

f1woxihuan 2017-11-10 06:37:14
大神们帮忙看看: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."
...全文
201 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
饺克力克 2017-11-12
  • 打赏
  • 举报
回复
应该是你的方法少了参数
AlbertLiangzt 2017-11-10
  • 打赏
  • 举报
回复

class Pen{
  private int ink = 100; 

	public int getInk() {
		return ink;
	}
	public void setInk(int ink) {
		this.ink = ink;
	}
}
class Paper{
  private String text;
  public void append() {
  }
}
剩下的自己看吧,基本就是把那段话打印出来,然后把五十个字符的空格用换行符替换,翻译不是很准确,凑合看吧
AlbertLiangzt 2017-11-10
  • 打赏
  • 举报
回复
确定没有进错片场?

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧