Hi,
i've been practicing again......my exam is tomorrow :( and this is another practice question that my instructor told us to practice on, its not that easy, it was from a past final exam paper, so please help me out. I only did one little bit of it, and im 100% sure that its wrong......plea se bear with me :(
Here's how it goes:
1.The implementation of the BadStudentScore s class presented in the figure above, uses two parallel arrays to keep track of the names and scores of students. We want to modify this program to eliminate the use of parallel arrays and to be able to store an undefined number of students. The skeleton of the new design includes three classes: “student”, “GoodStudentsSc ores” and a tester “StudentsScores Tester”
1) The class “student” keeps all the information related to a student; provide the declaration for the necessary attributes and methods so that the three classes (student,GoodSt udentsScores and StudentsScoresT ester) work together.
2) Provide the code of the methods of the class GoodStudentsSco res:
The figure below shows the skeletons for the three classes:
This is what I tried to do:
Can anyone please tell me how i can do the public void add(student stud) part and the public String getHighest() part??? pleaseeee!!!
thanks soooooooooooooo oooooooo much
outofmymind
i've been practicing again......my exam is tomorrow :( and this is another practice question that my instructor told us to practice on, its not that easy, it was from a past final exam paper, so please help me out. I only did one little bit of it, and im 100% sure that its wrong......plea se bear with me :(
Here's how it goes:
Code:
public class BadStudentScores { public BadStudentScores() { scores = new int[MAX_STUDENTS]; names = new String[MAX_STUDENTS]; numStudents = 0; } public void add(String name, int score){ if (numStudents >= MAX_STUDENTS) return; // not enough space to add new student score names[numStudents] = name; scores[numStudents] = score; numStudents++; } public String getHighest(){ if (numStudents == 0) return null; int highest = 0; for (int i = 1; i < numStudents; i++) if (scores[i] > scores[highest]) highest = i; return names[highest]; } private final int MAX_STUDENTS = 100; private String[] names; private int[] scores; private int numStudents; }
1) The class “student” keeps all the information related to a student; provide the declaration for the necessary attributes and methods so that the three classes (student,GoodSt udentsScores and StudentsScoresT ester) work together.
2) Provide the code of the methods of the class GoodStudentsSco res:
Code:
public GoodStudentsScores(); public void add(Student stud); public String getHighest();
Code:
public class student { // provide code here for constructor and necessary methods // provide declaration of attributes here } public class GoodStudentsScores { public GoodStudentsScores() { // provide code here .. } public void add(student stud){ // provide code here .. } public String getHighest(){ // provide code here .. } private ArrayList<student> data; } public class StudentsScoresTester { public static void main(String[] args) { String names [] = { "John", "Ali", "Layla"}; int scores [] = { 75 , 85, 95}; GoodStudentsScores board = new GoodStudentsScores(); for (int i=0; i < names.length;i++){ student s = new student(names[i], scores[i]); board.add(s); } System.out.println(board.getHighest() + " has the highest scores"); } } The output produced is: Layla has the highest scores
Code:
public class student { // provide code here for constructor and necessary methods public student(){ string studName = null; int Studscores=0; } public student (string studName, int studScores) { this. studName = studName; this. studScores = studScores; } public String getstudName () { return studName; } public void set studName(String studName) { this.studName = studName; } public int get studScores () { return studScores; } public void setstudScores (int studScores) { this.studScores = studScores; } // provide declaration of attributes here String studName; int studScores; public class GoodStudentsScores { public GoodStudentsScores() { // provide code here .. studName=null; studScores=0; } }
Can anyone please tell me how i can do the public void add(student stud) part and the public String getHighest() part??? pleaseeee!!!
thanks soooooooooooooo oooooooo much
outofmymind
Comment