Name : Date : ArrayList Worksheet 1 KEY
Name : ___________________________ Date : _________________
ArrayList Worksheet 1 KEY
DIRECTIONS : Fill in each blank with the correct answer/output. Assume each statement happens in order and that one statement may affect the next statement.
public class Student{ private String name; private int age;
public Student(String n, int a){ name = n; age = a;
}
public String toString(){ return name + " is " + age + " years old";
} }
ArrayList rayList = new ArrayList(); rayList.add(new Student("Sam", 17)); rayList.add(new Student("Sandra", 18)); rayList.add(new Student("Billy", 16)); rayList.add(new Student("Greg", 17)); rayList.add(new Student("Jill", 18));
System.out.println(rayList.get(0)); // LINE 1
1. Sam is 17 years old
System.out.println(rayList.get(1)); // LINE 2
2. Sandra is 18 years old
System.out.println(rayList.get(2)); // LINE 3
3. Billy is 16 years old
System.out.println(rayList.size()); // LINE 4
4. 5
System.out.println(rayList.remove(0)); // LINE 5
5. Sam is 17 years old
System.out.println(rayList); // LINE 6 System.out.println(rayList.remove(1)); // LINE 7 System.out.println(rayList); // LINE 8
6. [Sandra is 18 years old, Billy is 16 years old, Greg is 17 years old, Jill is 18 years old]
7. Billy is 16 years old
8. [Sandra is 18 years old, Greg is 17 years old, Jill is 18 years old]
Name : ___________________________ Date : _________________
ArrayList Worksheet 2 KEY
DIRECTIONS : Fill in each blank with the correct answer/output. Assume each statement happens in order and that one statement may affect the next statement.
public class Grade{ //data not shown
public Grade(double g){ //code not shown
}
public String getLetter(){ //gets letter grade associated with the numeric grade //code not shown
}
public String toString(){ return ""+String.format("%.2f",grade);
} }
//test code in a client class //instantiate an ArrayList of Grade references (objects) ArrayList grades = new ArrayList();
//write the code to load in 8 random Grade references ? use a for loop for(int i=0; i ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- chapter 7 arrays
- multiplication sentences and arrays worksheet
- arrays name grade worksheet 1 name mathseeds
- multiplication arrays printable math worksheets
- name date arraylist worksheet 1 key
- grade 3 multiplication worksheet k5 learning
- multiplication arrays super teacher worksheets
- grade 4 supplement the math learning center
- multiplication with arrays super teacher worksheets
- fourth grade ohio history unit kayla ross
Related searches
- significant figures worksheet 1 answers
- macmillan english 6 unit 6 worksheet student key to correction
- dna worksheet answer key pdf
- exponential equations worksheet 1 answers
- metric conversions worksheet 1 answers
- number tracing worksheet 1 10
- dna worksheet answer key biology
- geometry worksheet 1 1 answer key
- the cell cycle worksheet answer key pdf
- windows 8 1 key buy
- worksheet answer key finder
- cell membrane coloring worksheet answer key biology