Accomplish RandomCourse.java

解决方案 »

  1.   

    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.
      

  2.   

    创建类的时候就创建点标识符,比如都有一个相同的变量X,X取不同的值,然后做一个循环看有几个不同的X取值。
    仅仅是个想法,LZ自己再想想吧。
      

  3.   

    楼主不妨看看我这个程序:
    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);
    }
    }
      

  4.   

    哦,楼主上面代码有问题,下面这个是对的
    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);
    }
    }
      

  5.   

    针对从Shape衍生出来的所有东西,Shape建立了一个通用接口——也就是说,所有(几何)形状都可以描绘和删除。衍生类覆盖了这些定义,为每种特殊类型的几何形状都提供了独一无二的行为。
    在主类Shapes里,包含了一个static方法,名为randShape()。它的作用是在每次调用它时为某个随机选择的Shape对象生成一个句柄。请注意上溯造型是在每个return语句里发生的。这个语句取得指向一个Circle,Square或者Triangle的句柄,并将其作为返回类型Shape发给方法。所以无论什么时候调用这个方法,就绝对没机会了解它的具体类型到底是什么,因为肯定会获得一个单纯的Shape句柄。