Expand|Select|Wrap|Line Numbers
- import java.util.*;
- class Student
- {
- private String name;
- private int score;
- public Student()
- {
- name = "";
- score = 0;
- }
- public Student(String name, int score)
- {
- this.name = name; this.score = score;
- }
- public int getScore()
- {
- return score;
- }
- public String getName()
- {
- return name;
- }
- public String toString()
- {
- return name + " has a score of " + score;
- }
- }
Expand|Select|Wrap|Line Numbers
- class GoodStudentsScores
- {
- private ArrayList<Students>data = new ArrayList<Student>();
- public GoodStudentsScores()
- {
- data = new ArrayList<Student>();
- }
- public void add(Student stud)
- {
- data.add(stud);
- }
- public String getHighest()
- {
- int highest = 0;
- for(int i = 1; i < data.size(); i++)
- {
- if(data.get(i).getScore() > data.get(highest).getScore())
- {
- highest = i;
- }
- } return data.get(highest).getName();
- }
- }
Expand|Select|Wrap|Line Numbers
- 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");
- }
- }
----jGRASP exec: javac -g C:\Documents and Settings\Owner\My Documents\School\Computer Science II\StudentsScoresTester.java
GoodStudentsScores.java:3: cannot find symbol
symbol : class Students
location: class GoodStudentsScores
private ArrayList<Students>data = new ArrayList<Student>();
^
GoodStudentsScores.java:3: type ArrayList does not take parameters
private ArrayList<Students>data = new ArrayList<Student>();
^
GoodStudentsScores.java:3: type ArrayList does not take parameters
private ArrayList<Students>data = new ArrayList<Student>();
^
GoodStudentsScores.java:7: type ArrayList does not take parameters
data = new ArrayList<Student>();
^
4 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete
This is not my assignment. I was simply looking to other forums for any programs that came close to what I am trying to do. And this one was the closest. But I was hoping to get this one to compile and run so that I could better understand how the use of the parallel arrays is working. I'm confused on it. Can anyone help fix the errors so that I can make it run.