2012-08-26 77 views
-3

我有下面的問題,並想知道我是否解釋了這個問題是否正確。我對Java和編程非常陌生,所以技術術語甚至認爲我閱讀了我的教科書並理解了它們,如果我已經正確編寫了它們,我不確定。請看這個問題,讓我知道我正在做的是在正確的方向。java解釋正確

enter image description here

這個問題本身:

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? 
    } 

} 
+0

哈哈問了第一個問題,並得到了 - 我...這樣一個更寬鬆的我..是隻是我或stackoverflow不幫助開始程序員 – noobprogrammer

+0

您的問題涵蓋了非常簡單的OOP概念,有大量的例子和來源這可以幫助你改進你的代碼。所以不要期待看到這樣的問題。對我來說,我有很多空閒時間來回答你。 –

+1

提示:字符串「-ve」不是英語中的單詞。 – 2012-08-26 21:18:17

回答

2

一般可以,如果你採取其他答案中提出的意見。

但是,您的命名約定有點古怪。標準的java bean約定是用camelCase(所以markQuiz而不是mark_quiz)和你的getter和setter作爲getMarkQuiz和setMarkQuiz(get/set之後的第一個字母現在是大寫)命名你的屬性(你的整數等等)。對於布爾屬性,使用isXxx()而不是getXxx()。

這些約定被廣泛使用,將會使你的代碼更加工具型(與IDE如ecliipse /的NetBeans)

問候您的評論你的問題,家庭作業的問題是在一般皺着眉頭,這就是爲什麼你有後倒投了。通過玩和試驗,你會學到更多東西,弄錯它然後修復它,而不是來這裏尋求答案。至少你確實提供了一個骷髏答案,所以你正在考慮它,爲此做得非常好。保持它!

+0

感謝和+1指向camelCase符號,我完全忘了它指出我的答案,因爲我沒有用Java編碼一年或兩年。 –

+2

+1命名約定。 [「Java編程風格指南」](http://www.cwu.edu/~gellenbe/javastyle/naming.html)上的鏈接可能會派上用場! – Sujay

+0

Tks支持和指向正確的方向。我終於設法完成了我的任務。 – noobprogrammer