0

这是我的作业问题,但我似乎无法弄清楚。该程序提示用户输入学生人数,然后提示用户输入每个学生的成绩百分比(0-100)。唯一我无法做到的事情是我无法在正确的位置绘制列。列将相隔 0.5 个空格。请注意,学生人数将是水平轴,成绩将是垂直轴。我在代码中包含的评论是我需要帮助的。谢谢

import java.util.*;
import javax.swing.JOptionPane;


public class GradesChart{
  public static void main (String [] args) {

  drawAxes(); //Call method to draw the axes intersecting at (0.1,0.1)

  String input = JOptionPane.showInputDialog(null,"Please enter the number of students.");
  int input2 = Integer.parseInt(input);

  double columnnWidth = 0.5; // *** HOW TO CALCULATE THE COLUMN WIDTH???****

  for (int grade = 0; grade < input2; grade++){
      JOptionPane.showInputDialog(null, "Please enter the grade of student. ");
    drawColumn(columnnWidth, input2 , grade);
    /**IN THIS FOR LOOP I WANT TO PROMPT USER TO ENTER THE GRADE OF EACH STUDENT (0-100)
    AND DRAW A COLUMN THAT REPRESENTS THE GRADE **/
  }
  }

  public static void drawAxes() {
    StdDraw.setPenColor(StdDraw.BLACK);
    StdDraw.line(0.0,1.0,0.0,0.0);
    StdDraw.line(0.0,0.0,1.0,0.0);
  }

  public static void drawColumn(double width, int studentIndex, int grade) {
    StdDraw.setPenColor(StdDraw.BLUE);
    StdDraw.filledRectangle(studentIndex, grade, width, 1.0);
  }

}
4

1 回答 1

0

使用 JFreeCharts 库。请参阅此示例以获取更多信息:http ://www.tutorialspoint.com/jfreechart/jfreechart_bar_chart.htm

于 2015-03-12T17:22:38.857 回答