确定每个级别的学生人数



我是Java和Netbeans的新手。这就是我要做的:
显示每个级别中的学生人数(R,1、2、3、4)。

Level R (mark < 50)     
Level 1 ( (mark >= 50) && (mark < 60) )    
Level 2 ( (mark >= 60) && (mark < 70) )    
Level 3 ( (mark >= 70) && (mark < 80) )    
Level 4 (mark >= 80).

我需要使用一个数组,我知道它需要包含5个元素。我不知道该怎么做。但是,我没想到会了解您的整个代码,所以不要关闭问题。我只想知道的是提示或方法,所以我知道如何编写程序。感谢任何帮助,并提前感谢您!

这是可以让您开始的东西

    Point2D levelContainer[] = new Point2D[5];
    //set the R level
    levelContainer[0] = new Point2D.Double(0, 50);
    //set the rest
    levelContainer[1] = new Point2D.Double(50, 60);
    levelContainer[2] = new Point2D.Double(60, 70);
    levelContainer[3] = new Point2D.Double(70, 80);
    levelContainer[4] = new Point2D.Double(80, Double.MAX_VALUE);
    double exampleMark[] = {2, 56, 63, 70, 8080};
    for(int index = 0; index < exampleMark.length; index++)
    {
        //now for every mark we have, we need to loop the level array until we find the which level it falls in
        for(int levelIndex = 0; levelIndex < levelContainer.length; levelIndex++)
        {
            //now check the X, our minimum value, and the Y,our max value, for our range and if it does fall into the range print out the level
            if(exampleMark[index] >= levelContainer[levelIndex].getX() && exampleMark[index] < levelContainer[levelIndex].getY())
            {
                //basically use R if the level the mark falls into is 0
                String level = levelIndex == 0 ? "R" : new Integer(levelIndex).toString();
                System.out.println("Our current mark is " + exampleMark[index] + " which falls between " 
                        + levelContainer[levelIndex].getX() + " and " +
                        levelContainer[levelIndex].getY() + " which is level " + level);
            }
        }
    }

相关内容

  • 没有找到相关文章

最新更新