Question

edhesive Term 2 - Unit 5 Week 4 19. Consider the following code segment: ArrayList<Light bulbs - new ArrayList<light> (3 bulb

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Solution 19

ArrayList<Light> bulbs = new ArrayList<>();
//add Light
bulbs.add(new Light());
//remove light at index 0
bulbs.remove(0);
// add light
bulbs.add(new Light());
// create object of Light
Light b = new Light();
// add light at index 1
bulbs.add(1,b);
// add light
bulbs.add(new Light());
// remove light from index 0
bulbs.remove(0);
// add light
bulbs.add(new Light());
// remove light at index at index 2
bulbs.remove(2);
// add bulb
bulbs.add(new Light());

// Trick -> Count numbers of add and remove

// after subtracting add-remove we get the size

There six numbers of add and three numbers of remove

So the size is 3

Ans -> (b) 3

Solution (20)

An array list can hold only Wrapper types.

Ans: -> e

wrapper class can convert a primitive types (int , float , double, boolean, char)

to reference type(Integer, Float, Double, Boolean, Character etc.)

//Thanks

If you need any help regarding this solution....... please leave a comment...... thanks

Add a comment
Know the answer?
Add Answer to:
edhesive Term 2 - Unit 5 Week 4 19. Consider the following code segment: ArrayList<Light bulbs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following code segment. ArrayList<String> towns = new ArrayList<String> (); towns.add("Baltimore"); towns.add("Bethesda"); towns.add("Wheaton"); towns.add("Greenbelt"); towns.add("Rockville");...

    Consider the following code segment. ArrayList<String> towns = new ArrayList<String> (); towns.add("Baltimore"); towns.add("Bethesda"); towns.add("Wheaton"); towns.add("Greenbelt"); towns.add("Rockville"); for (int k = 1; k< towns.size(); k ++) System.out.print(towns.get(k) + " "); What is printed as a result of executing the code segment? Baltimore Bethesda Wheaton Greenbelt IndexOutOfBoundsException message Baltimore Bethesda Wheaton Greenbelt Rockville Bethesda Wheaton Greenbelt Rockville Refer to the doSomething method: public static void doSomething (ArrayList list, int i, intj) SomeType temp = list.get(i); list.set(i, list.get()); list.set(j, temp); Which best describes...

  • Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int...

    Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int k = n; k > 0; k--) seq.add(new Integer(k+3)); return seq What is the final output of the following Java statement? System.out.println(mystery(3)); a. [1,2,4,5) b. [2,3,4,5) c. [6,5,4,3] d. [7, 7, 8, 8] e. [7,8,9, 8) O Consider the following method: public static int mystery(int[] arr, int k) ifk-0) return 0; }else{ return arr[k - 1] + mystery(arr, k-1):) The code segment below is...

  • 1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer...

    1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code:     Person p1, p2, p3;     int m1, m2, m3;     p1 = new Person();     m1 = p1.getMoney();     // assignment 1...

  • 4. Consider the identical light bulbs (e) in the circuit to the right. Circuits 1, 2,...

    4. Consider the identical light bulbs (e) in the circuit to the right. Circuits 1, 2, 3, 4 are series circuits". I? 2 Circuits 5, 6, and 8 are "parallel circuits". 4 Some circuits have one battery, others have two batteries. 6 Now close the switch. Using the "brightness" of the bulb in the simple circuit 1 as the standard for normal" brightness, answer the following questions by specifying the circuit(s) number(s) 5 7 (a) Which circuits had bulbs that...

  • Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1;...

    Consider the following code segment. int[]arr={1, 2, 3, 4, 5, 6, 7, 8}; for(int k=3; k<arr.length-1; R++ arr[k]-arr[k+1]; What are the contents of arr as a result of executing the code segment? a. {1, 2, 3, 5, 6, 7, 8, 8) b. {2, 2, 4, 5, 6, 7, 8, 8} C. {2, 4, 6, 5, 6, 7, 8,8} d. {4, 2, 4, 4, 6, 7, 8, 8) e. {6, 6, 4, 5, 6, 7, 8, 8} int) arr={7, 2.5, 3.0,...

  • Consider the following time series data. Week 1 2 3 4 5 6 Value 19 14...

    Consider the following time series data. Week 1 2 3 4 5 6 Value 19 14 17 12 17 14 Develop a three-week moving average for this time series. Compute MSE and a forecast for week 7. Round your answers to two decimal places. Week Time Series Value Forecast 1 19 2 14 3 17 4 12 5 17 6 14 MSE: The forecast for week 7: Use = 0.2 to compute the exponential smoothing values for the time series....

  • Consider the following time series data Week 1 2 3 4 5 6 Value 19 14...

    Consider the following time series data Week 1 2 3 4 5 6 Value 19 14 16 12 18 15 a. Which of the following is a correct time series plot for this data? 1 Time eries Value 15 10 Week 2 TimeSeries Value 15 10 5 Week 4 3 TimeSeries Value 15 10 -5 Week 4 5 Select your answer What type of pattern exists in the data? What type of pattern exists in the data? Horizontal b. Develop...

  • 7 [24 marks] Consider the following MIPS code segment that is executed on a 5-stage pipeline architecture that does not implement forwarding or stalling in hardware. (1) add $4, $1, $1 (2) add $7,...

    7 [24 marks] Consider the following MIPS code segment that is executed on a 5-stage pipeline architecture that does not implement forwarding or stalling in hardware. (1) add $4, $1, $1 (2) add $7, $4, $9 (3) lw $2, 40($8) (4) sub $8, $1, $2 (5) sw $8, 80(S2) (6) sub $2, $8, $4 (7) lw S8, 2($1) (8) add $8, $4, S2 Identify the data dependences that cause hazards. You are to use the following format to inform each...

  • Program Overview This brief exercise is designed for you to consider how reference variables behave when...

    Program Overview This brief exercise is designed for you to consider how reference variables behave when you are passing them as arguments by-value. Instructions Name your class References.java. 1. Implement the following methods. 1.1 Method name: readStudentNames Purpose: This method accepts an array of strings as a parameter. It loops through the array and asks the user to input names. It populates the array of strings with the names. Parameters: an array of Strings, stringArray Return type: void In the...

  • Consider the following time series data. Week 1 2 3 4 5 6 Value 1914 16...

    Consider the following time series data. Week 1 2 3 4 5 6 Value 1914 16 10 19 13 Using the naïve method (most recent value) as the forecast for the next week, compute the following measures of forecast accuracy. a. Mean absolute error. Round your answer to one decimal place. b. Mean squared error. Round your answer to one decimal place. c. Mean absolute percentage error. Round your answer to two decimal places. d. What is the forecast for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT