如何将整数值添加到数组?

时间:2019-07-20 00:56:44

标签: java arrays user-interface

我正在尝试完成这项作业,我必须在GUI上创建一个带有学生分数的程序,并使用“添加分数”按钮将他们添加到数组中(jTextField) 。 “排序”按钮按升序对标记进行排序。 “计算”按钮通过计算班级平均成绩等来分析分数。

我在获取输入的标记以添加到数组时遇到问题。我尝试了使用字符串的方法,但是标记不会以“列表格式”显示,而是将它们替换为输入的新标记。我希望标记在数组中列出。...

  private void btnMarkActionPerformed(java.awt.event.ActionEvent evt) {                                        
        String mark, list;
        mark=txtMark.getText();
        txtList.setText(mark);

    }                                       

    private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {                                        
        double [] list;
        list = new double [36];
        for (int i = 0; i < list.length; i++)
        {
        this.txtList.setText(list[i] + " ");
        {
    }                                       

    private void btnCalculateActionPerformed(java.awt.event.ActionEvent 
    evt) {                                             
        double [] list;
        list = new double [36];

        //To find class marks sum: 
        double total = 0;
        for (int i = 0; i < list.length; i++)
        {
          total += list[i]; 
        }

        // To find class average:
        double average = total/list.length;
        this.txtAnalyze.setText("Class Average:" + average);

        // To find class max :
        double max = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < list.length; i++)
        {
            if (list[i] > max) max = list[i];
        }
        this.txtAnalyze.setText("Maximum Mark:" + max);

        // To find class min:
        double min = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < list.length; i++)
        {
            if (list[i] > min) min = list[i];
        }
        this. txtAnalyze.setText("Minimum Mark:" + min);

        // To find class range:
        double range = max - min;
        this.txtAnalyze.setText("Class Range:" + range);
    }

0 个答案:

没有答案