关于JAVA的小小的问题,望高手指点~

A198905011 2010-05-30 09:48:55
Accomplish RandomCourse.java

...全文
115 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
livs_ly_2010 2010-05-31
  • 打赏
  • 举报
回复
我一直在郁闷,英语没学好,天天记单词到底有没有用。 但是我还是迷茫的记着。一天10+个。价值投资吧。
A_JSir 2010-05-30
  • 打赏
  • 举报
回复
针对从Shape衍生出来的所有东西,Shape建立了一个通用接口——也就是说,所有(几何)形状都可以描绘和删除。衍生类覆盖了这些定义,为每种特殊类型的几何形状都提供了独一无二的行为。
在主类Shapes里,包含了一个static方法,名为randShape()。它的作用是在每次调用它时为某个随机选择的Shape对象生成一个句柄。请注意上溯造型是在每个return语句里发生的。这个语句取得指向一个Circle,Square或者Triangle的句柄,并将其作为返回类型Shape发给方法。所以无论什么时候调用这个方法,就绝对没机会了解它的具体类型到底是什么,因为肯定会获得一个单纯的Shape句柄。
  • 打赏
  • 举报
回复
哦,楼主上面代码有问题,下面这个是对的
import java.util.Random;
/**
* @author 不再悲伤
* Accomplish RandomCourse.java
*You have 4 classes representing different courses:
*=Accounting,Economics, Finance, and Informatics.You
*need to creat RandomCourse class, then:
*1. You randomly create n course objects (Here n = 99);
*2. You output the exact numbers for different course
*objects.
*/
public class RandomCourse
{
public static void main(String[] args)
{
int Accounting=0,Accounting1=0;
int Economics=1,Economics1=0;
int Finance=2,Finance1=0;
int Informatics=3,Informatics1=0;
int[] b=new int[100];
Random in=new Random(4);
for(int i=0;i<100;i++)
{b[i]=in.nextInt(3);}
for(int i=0;i<100;i++)
{
if(b[i]==0){Accounting1++;}
if(b[i]==1){Economics1++;}
if(b[i]==2){Finance1++;}
if(b[i]==3){Informatics1++;}
}
System.out.println("Accounting"+Accounting1);
System.out.println("Economics"+Economics1);
System.out.println("Finance"+Finance1);
System.out.println("Informatics"+Informatics1);
}
}
  • 打赏
  • 举报
回复
楼主不妨看看我这个程序:
import java.util.Random;
/**
* @author 不再悲伤
* Accomplish RandomCourse.java
*You have 4 classes representing different courses:
*=Accounting,Economics, Finance, and Informatics.You
*need to creat RandomCourse class, then:
*1. You randomly create n course objects (Here n = 99);
*2. You output the exact numbers for different course
*objects.
*/
public class RandomCourse
{
public static void main(String[] args)
{
int Accounting=0,Accounting1=0;
int Economics=1,Economics1=0;
int Finance=2,Finance1=0;
int Informatics=3,Informatics1=0;
int[] b=new int[100];
Random in=new Random(4);
for(int i=0;i<100;i++)
{b[i]=in.nextInt(3);}
for(int i=0,j=i+1;i<100;i++)
{
if(b[j]==b[i]){Accounting1++;}
if(b[j]==b[i]){Economics1++;}
if(b[j]==b[i]){Finance1++;}
if(b[j]==b[i]){Informatics1++;}
j++;
}
System.out.println("Accounting"+Accounting1);
System.out.println("Economics"+Economics1);
System.out.println("Finance"+Finance1);
System.out.println("Informatics"+Informatics1);
}
}
sniper4983 2010-05-30
  • 打赏
  • 举报
回复
创建类的时候就创建点标识符,比如都有一个相同的变量X,X取不同的值,然后做一个循环看有几个不同的X取值。
仅仅是个想法,LZ自己再想想吧。
dracularking 2010-05-30
  • 打赏
  • 举报
回复
yes, it's a random problem.

obviously four courses they have the equal randomness.
every course has 25 percent opportunity of becoming the one ninety-ninth.

at last sum up the occurrences of them all, among 99 course objects, how many times does each appear?

generally it's a 25 percent random event.

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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