-3

我有以下问题,想知道我是否正确解释了这个问题。我是 Java 和编程的新手,所以技术术语甚至认为我阅读了我的教科书并理解了它们,我不确定我是否正确地编程了它们。请查看问题并让我知道我正在做的事情是否朝着正确的方向发展。

在此处输入图像描述

问题本身:

You are asked to implement a class to keep track of the students' academic result for a module. The system requires the following information about a student:
 Student identification - a unique 7-digit identification that begins with 'S' for local students and 'F' for foreign student. E.g. S1234567.
 Student name
 Quiz mark - an integer number in the range of 0 to 100
 Assignment mark - an integer number in the range of 0 to 100
 Exam mark - a floating point number in the range of 0 to 100
 Resit student - true if the student is retaking the paper, false otherwise. Resit student does not have quiz and assignment marks.
Write a Java class called Student and provide the following:
 suitable instance variables for the information described above
 constructor(s) with the appropriate actions on the instance variables
 the accessor methods for the instance variables
 the computeScore() method to compute the score as follows:
for resit students, take only the exam mark as the score
for other students, score is calculated by using the formula
9% * quiz + 21% * assignment + 70% * exam
The score calculated is to be rounded up to the nearest integer and returned.
 the findGrade() method that returns the grade based on the score:

Score range
Grade
80 to 100
A
70 to 79
B
60 to 69
C
50 to 59
D
0 to 49
F
 the toString() method that returns the attribute values as a string with description.

那么这是我到目前为止的代码是否正确?我的意思是我声明构造函数的方式等等......tks

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package student_qn4;

/**
 *
 * @author 
 */
public class Student 
{
   private String student_idno, student_name;
   private int mark_quiz, mark_assig;
   private float mark_exam;
   private boolean student_resit;


   public Student (String id, String name , int quizM , int assignM , int examM) {

 studentId = id;
 studentName = name;
 quizMark = quizM;
 assignMark = assignM;
 examMark = examM;
 }

   public void setStudentnumber(String number)
   {
       student_idno = number;
   }

   public String getStudentnumber()
   {
       return student_idno;
   }

   public void setStudentname(String name)
   {
       student_name = name;
   }

   public String getStudentname()
   {
       return student_name;
   }

    public void setquizMark(int quizmarks)
   {
       mark_quiz = quizmarks;
   }

   public int getquizMark()
   {
       return mark_quiz;
   }


    public void setassigMark(int assigmarks)
   {
       mark_assig = assigmarks;
   }

   public int getassigMark()
   {
       return mark_assig;
   }


   public int computerScore()
   {
       /*do as the program asks then return the computer score */



   }



   public String findGrade()
   {
       // Based on the computeScore() I have to access what is the grade and return that
   }

   public String toString()
   {
       // What is this method supposed to do?
   }

}
4

1 回答 1

2

通常可以,如果您接受其他答案中的评论。

但是,您的命名约定有点古怪。标准的java bean约定是用camelCase(所以markQuiz而不是mark_quiz)命名你的属性(你的int等),你的getter和setter为getMarkQuiz和setMarkQuiz(get/set之后的第一个字母现在大写)对于布尔属性,使用 isXxx() 而不是 getXxx()。

这些约定被广泛使用,将使您的代码更加工具友好(使用诸如 ecliipse/netbeans 之类的 ide)

关于您提出问题后的评论,家庭作业问题通常不受欢迎,这就是您被否决的原因。与来这里寻求答案相比,您将通过玩耍和试验,弄错然后修复它来学到更多。至少您确实提供了一个框架答案,所以您正在考虑它,为此做得很好。坚持下去!

于 2012-08-26T08:39:30.150 回答