具有评分策略的类的Java评分程序

pas*_*o15 -3 java methods

我必须为具有以下评分政策的班级编写评分程序.

1.有2个测验,每个测验以10分为基础进行评分.

2.有1个期中考试和1个期末考试,每个考试分为100分.

3.期末考试占50%,期中考试为25%,2次测验共计25%.(不要忘记将测验分数标准化.)

将根据以下标准给出字母等级:90 - 100 A
80 - 89 B 70 - 79 C 60 - 69 D 0 - 59 E

该程序将从文本文件中读取学生的分数,并输出学生的记录,其中包括姓名,2个测验和2个考试分数,以及学生的整个课程和最终字母等级的平均数字分数.我想为学生记录定义和使用一个类.所有分数均为整数,学生姓名不超过10个字符.我必须证明你的输出文件.

这最初是由导师给出的,我不知道在哪里出演

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 );

    } 
  }
}
Run Code Online (Sandbox Code Playgroud)

pau*_*sm4 8

让我们走到这一步:

// 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';  
   }
   ...
Run Code Online (Sandbox Code Playgroud)

建议:

  1. 编写只是"编译"的最小的最小程序.

  2. 一次添加一件事.验证更改是否有效.

  3. 采取"婴儿步骤"到一个完整的解决方案.

  4. 根据需要回复有关特定问题的具体问题.

  • 1+.如果你没有使用IDE,那么经常编译***并立即修复任何发现的问题.在当前代码正确编译之前,请不要添加任何新代码. (4认同)
  • 他们正在帮助你.您需要从那里开始理解(以及编译什么)然后从那里构建.在代码中添加小东西,在编译之前不要移动到下一个部分.在main之外定义简单方法. (4认同)
  • @pasito:您从多个成员那里得到了很好的建议.不过,请不要期待或要求用勺子喂答案.如果您在实施建议时遇到特定问题,请询问具体问题,您可能会得到快速答案. (2认同)

car*_*ism 7

你的代码有很多问题,似乎根本不懂Java语法.不要试图定义主要的INSIDE方法.它们应该在主要之外定义.

我真的不知道从哪里开始,所以我建议你需要改变一件事:

if (finalScore >= 90)  
{  
grade = 'A';  
}  
if (finalScore >= 80)  
{  
grade = 'B';  
}
# etc...
Run Code Online (Sandbox Code Playgroud)

finalScore是的100.然后在第一个条件if将计算为truegrade将被分配'A'.然后是下一个if语句:100大于80,所以这也评估为true.你看到了问题吗? grade将被重新分配给'B'.

请阅读文档以了解如何else ifelse语句将在这里帮助您:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html (示例是如何实际分配成绩,确切的问题是你是工作!)