Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:紧急的问题,请高手们解释(理解英語題目) [Re:kof821117]
kof821117





发贴: 31
积分: 0
于 2006-01-18 10:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Assignment 4: A more sensible multiple copy function
(NB this was edited on Nov 11 to add a further method and on Nov 21 to add pseudocode)

make5Copy is a very inflexible way of making multiple copies. In this exercise
the makeCopy method is to be modified to make it more useful,
and a method makeCopies added that uses makeCopy to make multiple copies
an addPaper method is added as well

N B. The accessor methods getCopies() and getSheetsPaper() already written in cp02 are used to check that the Copying methods are being registered and that the number of sheets is reduced by them.

Make a new copy of the project and edit the Copier class as follows, remembering to use exactly the same name for the methods.

edit your makeCopy() to return a boolean, not an int pseudocode might be
public boolean makeCopy(String text)
should return a boolean (true or false) value.
This should be true if the copy was possible, and false if not.
It should not be possible to make a copy if there is no paper left!
declare a local boolean
assume false

if (there is paper left)
make copy
make boolean true

return boolean

create a new method to make multiple copies:
public int makeCopies(String text, int number)
This should try to make as many copies of the string as are passed to it as number
(so makeCopies("test",7) should produce 7 copies).
It should use makeCopy() to actually produce the copy.
If makeCopy() returns the boolean false,
makeCopies() should itself return an int, the number of copies still to be done.
declare a local boolean
assume true

while (there are copies to be made && boolean is true)
boolean = return value of makeCopy

if boolean is true
decrement number to be made

end while

return number of copies to be made


create a new method to increase the paper available
public int addPaper ( int n )
This should add n sheets of paper to those available provided n>0
It should return the number of sheets then available.
if n>0
numberofSheets += n ;


Testing code
The code used to test the Copier Class also uses methods previously written in Assignment 2: Note that the Copier class should still initialise the number of sheets to 10.

Copier c = new Copier();
c.testCopier();
if (c.makeCopy("makeCopy Works")) {
System.out.println("and registers copies made");
} else {
System.out.println("but doesn't register copies made correctly");
}
if (c.makeCopies("makeCopies Works", 5) == 0) {
System.out.println("and registers copies made");
} else {
System.out.println("but doesn't register copies made correctly");
}
// line below changed (for consistency only) on 22 November; output changed to match.
System.out.println("adding 1 sheet of paper: now there are " + c.addPaper(1) );
if (c.makeCopies("makeCopies Works", 8) == 3) {
System.out.println("and registers copies made, ");
System.out.println("and that there are 3 left to make");
} else {
System.out.println("but doesn't register copies made correctly");
}
System.out.println("Copies made = " + c.getCopies());
System.out.println("Sheets left = " + c.getSheetsPaper());

This should produce the output:

Copier Working
makeCopy Works
and registers copies made
makeCopies Works
makeCopies Works
makeCopies Works
makeCopies Works
makeCopies Works
and registers copies made
adding 1 sheet of paper: now there are 5
makeCopies Works
makeCopies Works
makeCopies Works
makeCopies Works
makeCopies Works
and registers copies made,
and that there are 3 left to make
Copies made = 11
Sheets left = 0




基于WEB的J2EE报表解决方案集锦

话题树型展开
人气 标题 作者 字数 发贴时间
14294 紧急的问题,请高手们解释(理解英語題目) kof821117 2027 2006-01-17 20:44
12050 Re:紧急的问题,请高手们解释(理解英語題目) why 173 2006-01-18 00:04
12511 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 403 2006-01-18 02:31
11944 Re:紧急的问题,请高手们解释(理解英語題目) why 535 2006-01-18 04:07
12548 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 2206 2006-01-18 04:31
12116 Re:紧急的问题,请高手们解释(理解英語題目) why 680 2006-01-18 04:52
12644 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 250 2006-01-18 09:57
11952 Re:紧急的问题,请高手们解释(理解英語題目) why 640 2006-01-18 10:11
12534 Re:紧急的问题,新的一个问题又来了,~~ kof821117 309 2006-01-18 10:03
12493 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 3610 2006-01-18 10:07
12086 Re:紧急的问题,请高手们解释(理解英語題目) why 2950 2006-01-25 12:14
12645 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 801 2006-01-18 00:26
12047 Re:紧急的问题,请高手们解释(理解英語題目) why 121 2006-01-18 00:32
12573 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 983 2006-01-18 00:43
12567 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 640 2006-01-18 00:45
12799 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 606 2006-01-18 00:51
11932 Re:紧急的问题,请高手们解释(理解英語題目) why 2705 2006-01-18 01:01
12561 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 75 2006-01-18 01:06
11994 Re:紧急的问题,请高手们解释(理解英語題目) why 259 2006-01-18 01:19
12644 Re:紧急的问题,请高手们解释(理解英語題目) kof821117 58 2006-01-18 01:35

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923