-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

あなたが他の答えでなされたコメントを船に乗せれば、一般的に大丈夫です。

ただし、命名規則は少し風変わりです。標準のJavaBeanの規則では、プロパティ(intなど)にcamelCase(mark_quizではなくmarkQuiz)を使用し、ゲッターとセッターにgetMarkQuizおよびsetMarkQuiz(get / setの後の最初の文字が大文字になります)という名前を付けます。 getXxx()ではなくisXxx()を使用します。

これらの規則は広く使用されており、コードをよりツールフレンドリーにします(ecliipse / netbeansなどのIDEを使用)

あなたの質問の後のあなたのコメントに関して、宿題の質問は一般的に眉をひそめます、それはあなたが投票されなかった理由です。ここに来て答えを求めるよりも、遊んで実験し、間違えてから修正することで、はるかに多くのことを学ぶことができます。少なくともあなたはスケルトンの答えを提供したので、あなたはそれについて考えています、それのためにとてもよくやった。それを続けてください!

于 2012-08-26T08:39:30.150 に答える