저는 자바와 프로그래밍에 익숙하지 않아, 제가 작업해온 프로젝트에 대한 도움을 받기를 희망했습니다.자바 클래스 임 플리 멘팅 및 메소드의 여러 조건 테스트
나는 Student라는 객체를 "시뮬레이트"하는 Java 클래스를 구현해야합니다. 이 클래스의 학생 객체는 학생 성적을 나타냅니다. 12 개의 변수, 3 개의 생성자, 12 개의 메소드가 있습니다.
각 학생 개체의 모든 데이터 입력란에 데이터를 채우고 배열에 각 학생 개체에 대한 참조를 저장하는 미리 작성된 응용 프로그램과 텍스트 파일 (여기에 표시되지 않음)이 있습니다.
가장 문제가있는 부분은 (1) 어떻게 생성자를 올바르게 만들 수 있습니까? (2) 인수를 취하는 setHomework와 같은 메소드를 올바르게 작성하고 메소드 내에서 여러 조건에 대해 을 비교하고이를 배열 요소에 할당하는 방법은 무엇입니까?
제공 할 수있는 도움에 미리 감사드립니다. 내가 말했듯이, 나는 아주 새롭기 때문에 거기에 확실한 은 많은 오류가있다. 어쨌든,이 불완전한 코드는 내가 지금까지 가지고 있습니다 :
public class Student{
private String name;
private String sid;
private double homework = NUM_HOMEWORK; //reference variable
private double quizzes = NUM_QUIZZES; //reference variable
private double exams = NUM_EXAMS; //reference variable
final static int NUM_HOMEWORK = 4;
final static int NUM_QUIZZES = 4;
final static int NUM_EXAMS = 2;
final static double HOMEWORK_MAX_POINTS = 5;
final static double QUIZ_MAX_POINTS = 20;
final static double MIDTERM_MAX_POINTS = 40;
final static double FINAL_MAX_POINTS = 60;
/*1st constructor. No-arg constructor. Sets object’s name variable to default value “Newstudent, A.” and object’s sid var to default of “0000000”. Also allocates 3 arrays; homework with length of NUM_HOMEWORK, quizzes with length of NUM_QUIZZES, and exams with length of NUM_EXAMS.*/
Student(){
name = "Newstudent, A";
sid = "0000000";
int[] homework = new int[NUM_HOMEWORK];
int[] quizzes = new int[NUM_QUIZZES];
int[] exams = new int[NUM_EXAMS];
}
/*2nd constructor. Takes 1 string arg and stores it in parameter newName. Param represents the name of a new Student object. Constructor sets object’s name var to the given newName and object’s sid var to default value of “0000000”. Also allocates same three arrays as first constructor.*/
Student(String newName) {
name = newName;
sid = "0000000";
int[] homework = new int[NUM_HOMEWORK];
int[] quizzes = new int[NUM_QUIZZES];
int[] exams = new int[NUM_EXAMS];
}
/*3rd constructor. Takes 2 string args and stores them in string params newName and newSid. Params represent the name and sid of a new Student object. Constructor sets object’s name var to the given newName and object’s sid var to the given newSid. Also allocates same three arrays as first constructor*/
Student(String newName, newSid){
name = newName;
newSid = "0000000";
int[] homework = new int[NUM_HOMEWORK];
int[] quizzes = new int[NUM_QUIZZES];
int[] exams = new int[NUM_EXAMS];
}
/*Method takes string arg and stores it in string newName. Sets object’s name variable to newName. Returns void.*/
public static void setName(String newName){
name = newName;
}
public static getName(){//Takes no args. Returns value of the object’s name variable.
return String name;
}
/*Takes 1 String arg and stores it in string param newSid. Sets object’s sid var to the given newSid. Returns void.*/
public static void setSid(String newSid){
sid = newSid;
}
/*Takes an int arg and stores it in int param homeworkNumber, and a double arg and stores it in double param score. Method checks if homeworkNumber is a # between 1 and NUM_HOMEWORK and if score is a # between 0 and HOMEWORK_MAX_POINTS. If both those conditions are true it assigns the corresponding element of the homework array the value of score. Example: if homeworkNumber is 1 and score is 5 the element homework[0] is assigned value of 5. Returns void.*/
public static void setHomework(int homeworkNumber, double score){
if(homeworkNumber > 1 && homeworkNumber < NUM_HOMEWORK && score > 0 && score < HOMEWORK_MAX_POINTS)
then score = homework;
}
/*Takes one int arg and stores it in a param homeworkNumber. Method returns one of the values in the object’s homework array. Method checks if homeworkNumber is # between 1 and NUM_HOMEWORK, and if this condition is true, method returns the double value at index homeworkNumber – 1 in the homework array. Otherwise, method returns 0. Method returns double.*/
public static getHomework(int homeworkNumber){
if(homeworkNumber > 1 && homeworkNumber < NUM_HOMEWORK)
then return homeworkNumber – 1;
else return 0;
}
/*Method takes an int param named quizNumberand and a double param named score. Method checks if quizNumber is a between 1 and NUM_QUIZZES and if score is between 0 and QUIZ_MAX_POINTS. If both conditions are true assigns the corresponding element of the quizzes array the value of score. Example: if quizNumber is 1 and score is 18 the element quiz[0] is assigned 18. Method returns void.*/
public static void setQuiz(int quizNumber, double score){
if (quizNumber > 1 && quizNumber < NUM_QUIZZES && score > 0 && score < QUIZ_MAX_POINTS)
quizzes = score;
}
/*Takes one int arg and stores it in param quizNumber. Returns one of the values in the object’s quizzes array. Method checks if quizNumber is between 1 and NUM_QUIZZES and if true returns the value at index quizNumber – 1 in the quizzes array. Otherwise, method returns 0. Method returns double.*/
public static getQuiz(int quizNumber){
if(quizNumber > 1 && quizNumber < NUM_QUIZZES)
return double quizNumber[] – 1
else return 0;
}
/*Takes one double args, stores it in param score. Checks if score is between 0 and MIDTERM_MAX_POINTS and if true, assign the element exams[0] the value of score. Returns void.*/
public static void setMidtermExam(double score){
if(score > 0 && score < MIDTERM_MAX_POINTS)
score = exams[0];
}
public static getMidtermExam(){//Takes no args. Return double value of exams[0].
return exams[0];
}
/*Takes one double arg, stores in in param score. Checks if score is between 0 and FINAL_MAX_POINTS and iff true assigns exams[1] the value of score. Method returns void.*/
public static void setFinalExam(double score){
if (score > 0 && score < FINAL_MAX_POINTS)
score = exams[1];
}
public static getFinalExam(){ //Takes no args. Returns double value of exams[1].
return exams[1];
}
/*Takes no args. Returns a String which the student object’s name, sid, homework scores, quiz scores and exam scores are concatenated.*/
public static toString(){
return "Student total information. " + name + ", " + sid + ", homework: " + homework + ", quizzes: " + quizzes + ", exams: " + exams;
}
}
생성자가있는 것 같습니다. 전달할 매개 변수가 더 필요하면 새로운 생성자를 생성 할 수 있습니다. 이러한 생성자에서 setHomework에 대한 논리가 필요한 경우 해당 값에 대한 setter를 호출 할 수 있습니다. IDE를 사용하는 경우 기본 코드가 생성되어야하며 거기에서 더 많은 기능을 추가 할 수 있습니다. 또한 생성자는 공개되어야합니다. – clinomaniac
공공 학생 (문자열 newName로, 문자열 newSid) {...} – clinomaniac
공공 정적 무효 setHomework (INT의 homeworkNumber, 이중 점수) { 경우 (homeworkNumber> 1 && homeworkNumber 0 && 점수
clinomaniac