473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

type ArrayList does not take parameters

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
6 14878
DeMan
1,806 1GB
I think you've declared a class Student (singular) and then tried to use a class Students (plural).....
Mar 4 '07 #2
schnag
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
schnag
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
r035198x
13,262 8TB
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
schnag
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
r035198x
13,262 8TB
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

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

Similar topics

8
by: Nader | last post by:
Hello all, In C# string is a reference type but I learned that string is different from other reference types such as class. For example, if you pass a string argument to a method and then...
6
by: Chris Simmons | last post by:
I know that a String is immutable, but I don't understand why this piece of code fails in nUnit: // BEGIN CODE using System; class Test { public static void Main( String args )
0
by: DaveR | last post by:
I have a webform with a two-column datagrid based on an Arraylist. The Arraylist draws the data for the two columns from two different tables in an SQL database. The data is displayed in datagrid...
2
by: Bernard Bourée | last post by:
I have defined a Class called EntSor (see code ) with a procedure Sub Définit which assign the values of this class. Then I have defined an Arraylist with Dim colEntSor As New ArrayList() ...
11
by: JohnR | last post by:
I'm trying to find a way to create a variable of a given type at runtime where I won't know the type until it actually executes. For example, dim x as object = "hi" x is declared as an object...
3
by: pgconnolly | last post by:
/* foreach does implicit type conversion on elements of a params argument or Generic.List. * This is not good. * Examples of evil follow... */ using System; // I love it when C# is strict...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
1
by: nasirmajor | last post by:
dear all, if anyone can help about inserting records into datagrid from arraylist. e.g i have a following sample,please anyone sujjest what can i change in it to make it better ArrayList...
13
by: looper | last post by:
Hi, i am having a problem as im new to c#. I did an arraylist and store my "uid" and want to put it into a row of pictures pic 1 , pic 2 , pic 3, pic 4 this is my code for putting the "uid"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.