By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

type ArrayList does not take parameters

P: 4
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. class Student
  3. {
  4.     private String name;
  5.    private int score;
  6.     public Student()
  7.     {
  8.     name = ""; 
  9.     score = 0;
  10.     }
  11.  
  12.     public Student(String name, int score)
  13.     {
  14.         this.name = name; this.score = score;
  15.     }
  16.  
  17.     public int getScore()
  18.     {
  19.         return score;
  20.     } 
  21.  
  22.     public String getName()
  23.     {
  24.         return name; 
  25.     } 
  26.  
  27.     public String toString()
  28.     {
  29.         return name + " has a score of " + score;
  30.     }
  31.  
Expand|Select|Wrap|Line Numbers
  1. class GoodStudentsScores
  2. {
  3.     private ArrayList<Students>data = new ArrayList<Student>();
  4.  
  5.     public GoodStudentsScores()
  6.     {
  7.         data = new ArrayList<Student>();
  8.     }
  9.  
  10.     public void add(Student stud)
  11.     { 
  12.          data.add(stud);
  13.     }
  14.  
  15.     public String getHighest()
  16.     { 
  17.         int highest = 0;     
  18.  
  19.         for(int i = 1; i < data.size(); i++)
  20.         { 
  21.             if(data.get(i).getScore() > data.get(highest).getScore())
  22.             {
  23.                  highest = i;
  24.              }
  25.         } return data.get(highest).getName();
  26.     }
  27.  
Expand|Select|Wrap|Line Numbers
  1. public class StudentsScoresTester
  2. {
  3.     public static void main(String[] args)
  4.     { 
  5.         String names [] = { "John", "Ali", "Layla"};
  6.        int scores [] = { 75 , 85, 95}; 
  7.         GoodStudentsScores board = new GoodStudentsScores();
  8.  
  9.     for (int i=0; i < names.length;i++)
  10.     { 
  11.         Student s = new Student(names[i], scores[i]); board.add(s);
  12.     } 
  13.     System.out.println(board.getHighest() + " has the highest scores");
  14.     } 
  15. }
  16.  
Can anyone tell me why this program gets compile errors of:
----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.
Mar 4 '07 #1
Share this Question
Share on Google+
6 Replies


DeMan
100+
P: 1,806
I think you've declared a class Student (singular) and then tried to use a class Students (plural).....
Mar 4 '07 #2

P: 4
ok corrected that but still get errors:

GoodStudentsScores.java:3: type ArrayList does not take parameters
private ArrayList<Student>data = new ArrayList<Student>();
^
GoodStudentsScores.java:3: type ArrayList does not take parameters
private ArrayList<Student>data = new ArrayList<Student>();
^
GoodStudentsScores.java:7: type ArrayList does not take parameters
data = new ArrayList<Student>();
^
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Mar 4 '07 #3

P: 4
Well, even though I couldn't get this example to work. I did manage to learn enough from it to get mine to compile and work. Thanks.
Mar 5 '07 #4

10K+
P: 13,264
Well, even though I couldn't get this example to work. I did manage to learn enough from it to get mine to compile and work. Thanks.
Is it compiling now?
Mar 5 '07 #5

P: 4
My actual program was different than this but still used parallel arrays. I was trying to get this program(posted program) to compile so I could better understand thee functioning of the arrays. The example I posted I did not get to compile or run. But from studying the code, the use of the parallel arrays from class to class, helped me to better understand so that I could get mine to work.

I actually think the errors are happening from the instantiating of the Array as:

private ArrayList<Student>data = new ArrayList<Student>();

for my program I did mine as:

MallList listOne = new MallList(names, costs, stores);

and I placed it in my testing class to call the MallItem Class

Not exactly sure if that was the only problem with the posted program...
Mar 6 '07 #6

10K+
P: 13,264
My actual program was different than this but still used parallel arrays. I was trying to get this program(posted program) to compile so I could better understand thee functioning of the arrays. The example I posted I did not get to compile or run. But from studying the code, the use of the parallel arrays from class to class, helped me to better understand so that I could get mine to work.

I actually think the errors are happening from the instantiating of the Array as:

private ArrayList<Student>data = new ArrayList<Student>();

for my program I did mine as:

MallList listOne = new MallList(names, costs, stores);

and I placed it in my testing class to call the MallItem Class

Not exactly sure if that was the only problem with the posted program...
What JDK version are you using? The code
Expand|Select|Wrap|Line Numbers
  1.  
  2. private ArrayList<Student>data = new ArrayList<Student>();
  3.  
only compiles on JDK 1.5 or higher
Mar 6 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.