具有评分政策的班级的 Java 评分程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11252268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java grading program for a class with grading policies
提问by pasito15
I have to write grading program for a class with the following grading policies.
我必须为具有以下评分政策的班级编写评分程序。
1.there are 2 quizzes, each graded on the basis of 10 points.
2.there is 1 midterm exam and one final exam, each graded on the basis of 100 points.
3.the final exam counts for 50% of the grade, the midterm counts for 25%, and the 2 quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores.)
1.有2个小测验,每个小测验以10分计分。
2.期中考试1次,期末考试1次,每门100分计分。
3.期末考试占成绩的50%,期中考试占25%,两次小测验合计占25%。(不要忘记标准化测验分数。)
A letter grade will be given based on the following criterion:
90 – 100 A
80 – 89 B
70 – 79 C
60 – 69 D
0 – 59 E
字母等级将根据以下标准给出: 90 – 100 A
80 – 89 B 70 – 79 C 60 – 69 D 0 – 59 E
The program will read in the student's scores from a text file, and output the student's record, which consists of the name, 2 quiz and 2 exam scores as well as the student's average numeric score for the entire course and final letter grade. I am suppose to define and use a class for the student record. All the scores are integers and a student name consists of no more than 10 characters. I must justify your output file.
该程序将从文本文件中读取学生的分数,并输出学生的记录,其中包括姓名、2 个测验和 2 个考试分数以及学生整个课程的平均数字分数和最终字母成绩。我想为学生记录定义和使用一个类。所有分数均为整数,学生姓名不超过 10 个字符。我必须证明你的输出文件是合理的。
this was originally given by the instructor I just don't know where to star
这个最初是老师给的,我就是不知道该从哪里开始
import java.until.*;
import java.io.*;
public class Assign7{
public static void main(String[] args)throws Exception{
Record.setGP(1.25, 1.25, 0.25, 0.50);
Scanner myIn = new Scanner( new File("scores.txt") );
public static void main getLetterGrade
if (finalScore > 90)
letter = 'A';
else if (finalScore > 80)
letter = 'B';
else if (finalScore > 70)
letter = 'C';
else if (finalScore > 60)
letter = 'D';
else
letter = 'F';
System.out.println( myIn.nextLine() +" avg "+"letter");
while( myIn.hasNext() ){
Record myR = new Record(myIn.next(), myIn.nextInt(), myIn.nextInt(), myIn.nextInt(),
myIn.nextInt());
System.out.println( myR );
}
}
}
回答by paulsm4
Let's just go this far:
让我们走到这一步:
// Why not "class" (lower case)?
// Should "class Assign7" be "public" (is it the main class in the module)?
// Did you put any "import" statements above this?
Class Assign7{
// Do you want to declare any member data before you start your "main()" function?
public static void main(String[] args)throws Exception{
// Is "Record.setGP()" a "static method"?
Record.setGP(1.25, 1.25, 0.25, 0.50);
// Isn't this class-wide data? If so, shouldn't you put it *above* "main()"?
int quiz1, quiz2;
int tMidterm, tFinal,tQuiz
int midterm = 0;
int finalExam = 0;
String name;
char grade;
// Do you really want to just bomb out of the program if this fails?
Scanner myIn = new Scanner( new File("scores.txt") );
// Whoa!!!! Why are we starting a new function, *inside of "main()"*?!?!
void getScore()
{
tQuiz = ((quiz1 + quiz2)/20)*.25;
tMidTerm = (midTermExam/100)*.25;
tFinal = (finalExam/100)*.50;
finalScore = tQuiz + tMidTerm + tFinal;
}
// It looks like we're starting a new function here, too.
// Where's your parenthesis and curly brace after "getLetterGrade"????
void getLetterGrade
if (finalScore >= 90)
{
grade = 'A';
}
// Supposing the grade was "99"?
// Would the student get a "B" here? Or even a "D" below???
if (finalScore >= 80)
{
grade = 'B';
}
...
SUGGESTION:
建议:
Write the smallest, minimal program that just "compiles".
Add one thing at a time. Verify that the change works.
Take "baby steps" to a complete solution.
Post back specific questions about specific problems as needed.
编写仅“编译”的最小的、最小的程序。
一次添加一件事。验证更改是否有效。
采取“婴儿步骤”来获得完整的解决方案。
根据需要回发有关特定问题的特定问题。
回答by carmenism
You have a lot of problems with your code and do not seem to understand Java syntax at all. Do not try to define methods INSIDE of main. They should be defined outside of the main.
您的代码有很多问题,而且似乎根本不了解 Java 语法。不要尝试在 main 的内部定义方法。它们应该在 main 之外定义。
I don't really know where to start so I'll suggest one thing you need to change badly:
我真的不知道从哪里开始,所以我建议你需要彻底改变一件事:
if (finalScore >= 90)
{
grade = 'A';
}
if (finalScore >= 80)
{
grade = 'B';
}
# etc...
Say the finalScore
is 100
. Then the condition in the first if
will evaluate to true
and grade
will be assigned 'A'
. Then the next if
statement: 100 is greater than 80 so this also evaluates to true
. Do you see the problem? grade
will be reassigned to 'B'
.
说finalScore
是100
。然后在第一个条件if
将计算为true
和grade
将被分配'A'
。然后下一个if
语句: 100 大于 80 所以这也计算为true
。你看到问题了吗? grade
将被重新分配给'B'
.
Please read the documentation to understand how else if
and else
statements will help you here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html(The example is how to assign grades actually, the exact problem you are working on!)
请阅读文档以了解如何else if
和else
语句将在此处为您提供帮助:http: //docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html(示例是如何实际分配成绩,您的确切问题是工作中!)