0

我需要这方面的帮助..我需要存储标准值以供以后使用..例如..我输入

  • 标准(1):测验
  • 百分比:25

  • 标准(2):出勤率
  • 百分比:75

然后程序会问

  • 学生姓名:JavaStack
  • 标准 1 的等级(即测验):92.52
  • Criteria2的等级(即出勤):86.35

我知道如何做其余的事情,但我不知道如何使 Criteria 值被存储以用于其余的评分性能。

    System.out.println("How many criteria?");
    System.out.print("Answer: ");
    crit1=Integer.parseInt(inpt.readLine());

    String critr;
    int perc;

    for(int crit=1; crit<=crit1; crit++){

        if(crit1==1){
            System.out.println("Criteria(1): ");
            critr=inpt.readLine();
            System.out.println("Percentage: 100%");
            perc=100;
        }

        System.out.print("Criteria("+ crit +"): ");
        critr=inpt.readLine();

        System.out.println("Input between 1-100 only");
        System.out.print("Percentage: ");
        perc=Integer.parseInt(inpt.readLine());
    }


    int grade;
    for(int name1=1; name1<=stud; name1++){
        System.out.println("Student's Name: ");
        name=inpt.readLine();

        System.out.println("Grade for " +critr+": ");
        grade=Integer.parseInt(inpt.readLine());
    }

是的,这是一项学校作业,我真的需要帮助。我希望你能帮助我。提前致谢!再会。

4

1 回答 1

0

创建一个自定义类的数组来存储数据

class Criteria {

    public Criteria (String name, float weight) {
        this.name = name;
        this.weight = weight;
    }

    public String name;
    public float weight
}

System.out.println("How many criteria?");
System.out.print("Answer: ");
int critCount =Integer.parseInt(inpt.readLine());

Criteria[] sections = new Criteria[critCount];

for(int crit=0; crit < critCount; crit++){

    System.out.println("Criteria(1): ");
    String name = inpt.readLine();
    System.out.println("Percentage: 100%");
    float value = Float.parseFloat(inpt.readLine());

    sections[i] = new Criteria(name, value);
}

// ...
于 2013-10-16T01:59:03.053 回答