Name two differences between an Array and an ArrayList? ArrayList band = new Arr
ID: 3664493 • Letter: N
Question
Name two differences between an Array and an ArrayList?
ArrayList band = new ArrayList();
Player p1 = new Player(“Joe”, 12, “Center”);
Write the code to add the Player object (p1) to the ArrayList.
Given that there is an ArrayList named list that contains 5 Player objects, write the code to call and output the getPoints() method of the third element in list. The getPoints() method accepts no parameters and returns an int value.
Given that there is an ArrayList named staff that contains Employee Objects, write the code that will loop through staff, calling and outputting the toString() method for each Employee object.
ArrayList<Integer> list = new ArrayList<Integer> ();
int num = 14;
Write the code to add the value contained in num to the ArrayList. Remember that ArrayLists can only hold objects.
Complete method getTotalPoints, which returns the total points of a given set of objects.
//precondition: list is a non-empty ArrayList containing Player objects.
//postcondition: returns the total of the int values stored in the points
field of the Player objects contained inside the ArrayList.
//the Player class contains method getPoints() which returns the point field
of the Player object.
public static int getTotalPoints (ArrayList<Player> list){
Explanation / Answer
ArrayList band=new ArrayList() ;
Player p1=new Player( “Joe” , 12, “Center” );
Answer: band.add( p1 ) ;
public int getPoints() {
int b=list.get( 3 )
return b ;
}
for( int j = 0 ; j < staff.size() ; j++ ) {
System.out.print( staff.get(j).toString() ) ;
}
ArrayList<Integer> list=new ArrayList<Integer> () ;
int num =14;
Integer b =new Integer ( num );
list.add ( b ) ;
public static int getTotalPoints( ArrayList<Player> lists ){
int values ;
for ( int j= 0 ; j< lists.size() ; j++ ){
int values=list.getPoints( j );
int values++ ;
}
return values ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.