Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Beginner - Need help with ArrayList<>!

$
0
0
I need to create an ArrayList type Test, but it keeps saying the add method(int,Test) is not applicable for the arguments (int). Im a beginner so be nice if its something really stupid. If I put it type Integer it works but its for a class and she wont let me do it that way. Any help would be greatly appreciated. Another error that I am also getting is the operator += is undefined for the argument types int,Test.

import java.util.ArrayList;
public class Student {
	private ArrayList<Test> test = new ArrayList<Test>();
	private String studentName;
	private int max;
	private int min;
	
	public Student(String name)
	{
		studentName = name;
	}
	public void addTestScore(int s)
	{
		test.add(s);
	}
	public ArrayList<Test> printTestScore()
	{
        return test;
	}
	public double getAverage(double avg, int total)
	{
		for(int i = 0;i<test.size();i++)
		{
			total+=test.get(i);
		}
		avg = total / test.size();
		return avg;
	}
	public int getMax()
	{
		for(int i = 0;i<test.size();i++)
		{
			if(i==0)
				max = test.get(i);
			else if(max<test.get(i))
				max = test.get(i);
		}
		return max;
	}
	public int getMin()
	{
		for(int i = 0;i<test.size();i++)
		{
			if(i==0)
				min = test.get(i);
			else if(test.get(i)<min)
				min = test.get(i);
		}
		return min;
	}
	
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>