Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中基于表分配成绩_Java_Arrays_Loops_For Loop_While Loop - Fatal编程技术网

在Java中基于表分配成绩

在Java中基于表分配成绩,java,arrays,loops,for-loop,while-loop,Java,Arrays,Loops,For Loop,While Loop,我一直在做的这个家庭作业是关于让用户输入他们的考试分数和家庭作业分数,然后使用以下表格为他们分配分数: 到目前为止,我们还没有了解数组,只是有一些基本的循环。有没有办法使用for或while循环而不是几十个if语句来实现这一点?这就是我到目前为止所做的: import java.util.Scanner; public class GradeCalculator { public static void main(String[] args) { // TODO Auto-gene

我一直在做的这个家庭作业是关于让用户输入他们的考试分数和家庭作业分数,然后使用以下表格为他们分配分数:

到目前为止,我们还没有了解数组,只是有一些基本的循环。有没有办法使用for或while循环而不是几十个if语句来实现这一点?这就是我到目前为止所做的:

import java.util.Scanner;

public class GradeCalculator {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner scanner = new Scanner(System.in);
    int numberOfAssignments = 7;
    int numberOfLabs = 16 ;
    int totalAssignmentScore;
    int totalLabScore;
    int totalTestScore = 0;
    int totalHomeworkScore = 0;
    int zyante;
    int attendance;
    int midterm1;
    int midterm2;
    int finalTest;
    int quizScore;
    int pat;


    for (int i = 1; i < numberOfAssignments; i++) {
        System.out.println("Enter your score obtained in Assignment No."+ i + ":");
        totalAssignmentScore = scanner.nextInt();
        {
            totalHomeworkScore += totalAssignmentScore;
            System.out.println(totalHomeworkScore);
        }

    }
    for (int i = 1; i < numberOfLabs; i++) {
        System.out
                .println("Enter your score obtained in Lab No." + i + ":");
        totalLabScore = scanner.nextInt();
        {
            totalHomeworkScore += totalLabScore;
            System.out.println(totalHomeworkScore);
        }
    }
    System.out.println("Enter your score obtained in Zyante: ");
    zyante = scanner.nextInt();
    totalHomeworkScore +=zyante;

    System.out.println("Enter your total score obtained in Attendance: ");
    attendance = scanner.nextInt();
    totalHomeworkScore += attendance;

    System.out.println("Enter your Midterm no. 1 score: ");
    midterm1 = scanner.nextInt();
    totalTestScore += midterm1;

    System.out.println("Enter your Midterm no. 2 score: ");
    midterm2 = scanner.nextInt();
    totalTestScore += midterm2;

    System.out.println("Enter your Final exam score: ");
    finalTest = scanner.nextInt();
    totalHomeworkScore += finalTest;

    System.out.println("Enter your total score in the in-class Quizzes: ");
    quizScore = scanner.nextInt();
    totalHomeworkScore += quizScore;

    System.out.println("Enter your score for PAT: ");
    pat = scanner.nextInt();
    totalHomeworkScore += pat;


    System.out.println("Your total test score is: " + totalTestScore );
    System.out.println("your total homework score is: " + totalHomeworkScore);





}
}
import java.util.Scanner;
公共班级成绩计算器{
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
扫描仪=新的扫描仪(System.in);
int numberOfAssignments=7;
int numberOfLabs=16;
整数总赋值分数;
int-core;
int totalTestScore=0;
int totalHomeworkScore=0;
int zyante;
国际出席;
国际中期1;
国际中期2;
国际终审法院;
int quizScore;
int pat;
for(int i=1;i
如果你真的不应该使用数组,那么你只需要分析你的数组并从中提取逻辑

从以下内容开始:

enum Grade {
  P,
  A,
  G;
}

public Grade score ( int tests, int homework ) {
  if ( homework <= 599
          || tests <= 149 ) {
    return Grade.P;
  }
  return Grade.G;
}
枚举等级{
P
A.
G
}
公开成绩(智力测验、智力作业){

如果你想输出
totalTestScore+totalHomeworkScore=GRADE
,其中GRADE是
G
A或
P`?这只是一个任意的表,还是你能根据这两个分数计算出一个分数?我们不能将两者相加,所以它必须是这样的“如果你的考试成绩是X,你的家庭作业成绩是Y,那么你通过/不通过该课程”因此,如果你的成绩是G或A,你通过该课程如果截止值是任意的,那么你需要学习数组,如果有算法,那么你可以使用它。你学习过整数除法/模吗?如果你有(实际上,即使你没有),您可以使用这些将问题简化为一些特殊情况以及考试和家庭作业分数的线性组合。请注意,“G”区域由左上角到右下角的一条线包围,再加上左侧的一些“凸起”。如果
T,请注意分数为“P”
public Grade score ( int tests, int homework ) {
  if ( homework <= 599
          || tests <= 149 
          || (homework <= 719 && tests <= 179 )) {
    return Grade.P;
  }
  return Grade.G;
}