一道Java编程题目!!求高手写下程序!跪谢~!!!

要用以下两个API:TypeAPI:http://www.cse.yorku.ca/common/type/api/index.htmlJavaAPI:http://ww... 要用以下两个API:

Type API: http://www.cse.yorku.ca/common/type/api/index.html
Java API: http://www.cse.yorku.ca/common/java/api/index.html

开头一定要用这样写(这个是硬性要求):
import java.io.PrintStream;
import java.util.Scanner;
import type.lib.*;

public class LEx9
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
PrintStream output = System.out;

// Prompt for and set seed.
output.print("Enter seed: ");
Fraction.setSeed(input.nextInt());

// Your code goes here...

}
}

然后最后Run出来的结果大概是这样的:

Run #1:

Enter seed: 500
Enter number of objects: 0
Generated Fraction Objects:
Percent Money: NaN
Percent Mixed: NaN
Percent Fract: NaN

Run #2:

Enter seed: 500
Enter number of objects: 1
Generated Fraction Objects:
1: + 822 185/566
Percent Money: 0.00
Percent Mixed: 100.00
Percent Fract: 0.00

Run #3:

Enter seed: 500
Enter number of objects: 12
Generated Fraction Objects:
1: + 822 185/566
2: 707/633
3: $1,529 dollars and 54 cents.
4: - 548 11/350
5: 267/347
6: 151/118
7: $2,557 dollars and 8 cents.
8: $1,883 dollars and 40 cents.
9: $1,289 dollars and 98 cents.
10: $1,602 dollars and 58 cents.
11: $2,446 dollars and 33 cents.
12: $2,431 dollars and 3 cents.
Percent Money: 58.33
Percent Mixed: 16.67
Percent Fract: 25.00

然后getRandom只能用Money 这个Object里面的。

其中Percent Money,Percent Mixed和Percent Fract 的和
加起来要正好等于100.00

求各位大神给个靠谱的CODE~!!
最后附上原地址~!
http://www.cse.yorku.ca/~roumani/course/1020/LEx9/
.
展开
 我来答
百度网友fc9fe86
2013-04-01 · 超过57用户采纳过TA的回答
知道小有建树答主
回答量:139
采纳率:0%
帮助的人:135万
展开全部
public class LEx9 {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
PrintStream output = System.out;
output.print("Enter seed: ");
Fraction.setSeed(input.nextInt());
output.print("Enter number of objects:");
LEx9 lEx9 = new LEx9();
FractionSequence fractionSequence = lEx9.new FractionSequence(
input.nextInt());
output.println("Generated Fraction Objects:");
for (int i = 1; i <= fractionSequence.size; i++) {
Fraction fraction = Money.getRandom();
output.println(" " + i + ":" + fraction);
fractionSequence.addFraction(fraction);
}
output.println("Percent Money: " + fractionSequence.getMoneyRate());
output.println("Percent Mixed: "
+ fractionSequence.getMixedNumberRate());
output.println("Percent Fract: " + fractionSequence.getFractionRate());
}

class FractionSequence {
private static final double BASE_RATE = 100.0;
public static final String RATE_FORMAT = "00.00";
private List<Fraction> franctions;
private int franctionCount, mixedNumberCount, moneyCount;
private int size;

public FractionSequence(int count) {
size = count;
franctions = new ArrayList<Fraction>(count);
}

public void addFraction(Fraction fraction) {

if (fraction instanceof Money) {
moneyCount++;
} else if (fraction instanceof MixedNumber) {
mixedNumberCount++;
} else {
franctionCount++;
}
franctions.add(fraction);
}

public String getFractionRate() {
return dealRate(franctionCount, size);
}

public String getMixedNumberRate() {
return dealRate(mixedNumberCount, size);
}

public String getMoneyRate() {
return dealRate(moneyCount, size);
}

private String dealRate(int source, int all) {
if(franctions.isEmpty())
return "NaN";
double rate = (source * BASE_RATE) / all;
BigDecimal bd = new BigDecimal(rate);
bd.setScale(2,BigDecimal.ROUND_UP);
return new DecimalFormat(RATE_FORMAT).format(bd.doubleValue());
}
}
}
我是_一只_鱼
2013-04-01
知道答主
回答量:2
采纳率:0%
帮助的人:2964
展开全部
表示代码很简单,但是文档就看不懂了,英语弱势群体的飘过。。
追问
简单的话拜托能不能写出来啊,我刚开始学Java。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ytffhvk316
2013-04-01
知道答主
回答量:17
采纳率:0%
帮助的人:7万
展开全部
这个程序太简单了
追问
简单的话拜托能不能写出来啊,我刚开始学Java。
追答
public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World!");
}
}

这个够简单吧,JAVA入门程序。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式