I need help with some java code?
me again. I need some help with some more extra credit to pull my grade up. The teacher gave me this code
import java.util.ArrayList;
public class ScoreSet
{
private ArrayList <Integer> scores;
public ScoreSet ( )
{
scores = new ArrayList<Integer> ( );
}
public void add (int score)
{
Integer wrapper = new Integer (score);
scores.add (wrapper);
}
public double averageWithoutLowest2 ( )
{
. . .
}
private ArrayList <Integer> scores;
}
she wants me to change the add method so that it uses auto-boxing instead of explicitly creating a wrapper.
i dunno what that means or how to do it. Please help me. Thank you.
I need help with some java code?
In java, a whole number, or an integer, can be represented in one of two different ways. 1) as a primitive (which is faster), or 2) as an object wrapper which is used when a variable has to be an object and can't be a primitive.
Here's how the add method can be made with auto-boxing:
public void add (int score) {
scores.add (score);
}
Notice that the method, add() takes a primitive int as a parameter and passes it into the ArrayList called scores, which puts the Integer at the end the array list as a new object. The conversion from int to Integer is done automatically. This is "auto-boxing".
I think that the source code that you have has some typos in it. I think that you need to remove the ellipse:
...
and I believe that it is an error to declare the variable called "scores" twice. That is, the following line of code should only be in once:
private ArrayList <Integer> scores;
- C++......................?
- is there a less complicated c++ compiler than microsoft express 2008? i found it to complicated and hav found no other free program to make a fps. a t..
- C++???????
- I am trying to make a tic tac toe game for c++ but i dont know how to use an array to make the board. also after i make the board hiw do i code it so ..
- C++???????????????
- I HAVE NO IDEA WHAT C++ IS? and i have an exam tomorrow. I dont understand 1. character set 2.tokens. i also have the for statement program, if stat..
- C++..........................?
- where i find the best c++ programing books.C++..........................?AT www.esnips.com/C++..........................?Try doing a search. OReilly t..
- C++????????
- i need to know a simple program to concat two strings without using strcat inside operator overloading.plz help me with a program..............C++????..
- ...................c++?
- How would I create a program that that displays the sum of a sales amount in each of 4 regions, during a 3 month period, which would also display the ..
- "Smitfraud-C. Toolbar888&..
- I am a webmaster, and I am trying to build my website, but my computer keeps acting weird and seems to be going into random hybernation for no reason ..
- C programme...?
- I wrote a programme of calculator in C language. And it has two or three error so pl do correct them. And send me correct answer. Prog. is: #includest..
- C programme...?
- I wrote a programme of calculator in C language. And it has two or three error so pl do correct them. And send me correct answer. Prog. is: #includest..
- C programme...?
- I wrote a programme of calculator in C language. And it has two or three error so pl do correct them. And send me correct answer. Prog. is: #includest..
