I am very inexperienced with java and therefore not very good at it. I am attemp
ID: 670224 • Letter: I
Question
I am very inexperienced with java and therefore not very good at it. I am attempting to write the code based on the following source code and I am struggling a great deal. Please help me.
/**
* clear()
*
* Called when the Clear button is clicked. Clears all of the text fields by setting the contents to the empty string.
* After clear() returns, no student information is being edited or displayed.
*
* PSEUDOCODE:
* Set the mSearchText text field to ""
* Set each of the homework text fields to ""
* Set each of the exam text fields to ""
* Set the mStudent reference to null
*/
??????
/**
* displayStudent()
*
* Displays the homework and exam scores for a student in the mHomeworkText and mExamText text fields.
*
* PSEUDOCODE:
* For i = 0 to CourseConstants.NUM_HOMEWORKS - 1 Do
* int hw = pStudent.getHomework(i)
* String hwstr = convert hw to a String (Hint: Integer.toString())
* mHomeworkText[i].setText(hwstr)
* End For
* Write another for loop similar to the one above to place the exams scores into the text fields
*/
public void displayStudent()
??????
/**
* saveStudent()
*
* Retrieves the homework and exam scores for pStudent from the text fields and writes the results to the Student record
* in the Roster.
*
* PSEUDOCODE:
* For i = 0 to CourseConstants.NUM_HOMEWORKS - 1 Do
* String hwstr = mHomeworkText[i].getText()
* int hw = convert hwstr to an int (Hint: Integer.parseInt())
* Call pStudent.setHomework(i, hw)
* End For
* Write another for loop similar to the one above to save the exam scores
*/
????????
Explanation / Answer
public class PStudent {
private String mSearchText ;
private int[] homeworkScores;
private int[] examScores;
private String[] mHomeworkText;
private String[] mExamText;
public PStudent() {
homeworkScores = new int[CourseConstants.NUM_HOMEWORKS];
examScores = new int[CourseConstants.NUM_EXAMS];
mHomeworkText = new String[CourseConstants.NUM_HOMEWORKS];
mExamText = new String[CourseConstants.NUM_EXAMS];
}
public void saveStudent(String[] mHomeworkText, String[] mExamText ) {
for(int i=0; i < CourseConstants.NUM_HOMEWORKS; i++) {
String hwstr = mHomeworkText[i];
int hw = Integer.parseInt(hwstr);
this.setHomeworkScore(i, hw);
}
for(int i=0; i < CourseConstants.NUM_HOMEWORKS; i++) {
String sstr = mExamText[i];
int score = Integer.parseInt(sstr);
this.setExamScore(i, score);
}
}
public void displayStudent() {
for(int i=0; i < CourseConstants.NUM_HOMEWORKS; i++) {
int hw = this.getHomeworkScore(i);
mHomeworkText[i] = Integer.toString(hw);
}
/* Write another for loop similar to the one above to place the exams scores into the text fields
*/
for(int i=0; i < CourseConstants.NUM_EXAMS; i++) {
int hw = this.getHomeworkScore(i);
mHomeworkText[i] = Integer.toString(hw);
}
}
public String getmSearchText() {
return mSearchText;
}
public void setmSearchText(String mSearchText) {
this.mSearchText = mSearchText;
}
public int[] getHomeworkScores() {
return homeworkScores;
}
public int getHomeworkScore(int i) {
return homeworkScores[i];
}
public void setHomeworkScore(int i, int hw) {
this.homeworkScores[i] = hw;
}
public void setHomeworkScores(int[] homeworkScores) {
this.homeworkScores = homeworkScores;
}
public int[] getExamScores() {
return examScores;
}
public void setExamScores(int[] examScores) {
this.examScores = examScores;
}
public int getExamScore(int i) {
return examScores[i];
}
public void setExamScore(int i, int score) {
this.examScores[i] = score;
}
public String[] getmHomeworkText() {
return mHomeworkText;
}
public void setmHomeworkText(String[] mHomeworkText) {
this.mHomeworkText = mHomeworkText;
}
public String[] getmExamText() {
return mExamText;
}
public void setmExamText(String[] mExamText) {
this.mExamText = mExamText;
}
}
class CourseConstants {
public static int NUM_HOMEWORKS = 5;
public static int NUM_EXAMS = 6;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.