AP Computer Science A: Arrays (Searching)

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

String s = "Confusing Syntax!"; Int size = s.length(); ///what integer value is assigned to size???

17

Which of the two example code is the formal parameter? A) public Candy (string na, int cal, boolean sour) B) Candy item0 = new Candy("AirHeads, 300, true);

A (declares the variables for which values will be assigned by the actual parameter, specific values)

Create a method, a constructor that constructs an empty list.

ArrayList( )

//Construct an array List for AP Exams2020

ArrayList<APExams2020> myAPExams = Arraylist<APExams2020>( );

//Make an array list of integers

ArrayList<Integer> arrayOfInts = new Arraylist<Integer( );

//Make an array list of mini figures that you name "myMinis"

ArrayList<MiniFigures> MyMinis = new ArrayList<MiniFigures>();

Every program statement enclosed in parenthesis _____________ a formal or actual parameter. A) is B) is not

B

int count = 0; for (int num: arr) if (num % 2 ==0) count=count+1; return count; //What does the program above do??? A) Returns the # of odd integers in array arr of integers. B) Returns the # of even integers in array arr of integers. C) Returns all the integers in array arr of integers. D) creates an out of bounds exception due to an improper use of modulus

B

Which of the two example code is the actual parameter? A) public Candy (string na, int cal, boolean sour) B) Candy item0 = new Candy("AirHeads, 300, true);

B (contains the values that are to be assigned to the formal parameter)

Public static void changeEven(int[]arr) { For (int i=0;i<arr.length;i=+2) arr[i] =0; } //What does the above program do??? A) Change each odd-indexed element in array arr to even. B) Créate new even-needed elements in array arr. C) Change each even-indexed element in array arr to 0. D) Change each odd-indexed element in array arr to 0 E) Modifies and creates array elements to create a new even array arr.

C

for (Integer num : list) { If (num<0) list.add(0); What is the result of the program above???

ConcurrentModificationException (it is okay, however, to use an enhanced for loop to modify objects that have a mutator method in their class definition)

//What do all 3 program below do? Double[] data = new double[25]; Double data[] = new double[25]; Double[] data; Data= new double[25];

Creates an array of 25 double values and assigns the reference data to this array

Create a method that Returns the element at the specified index in the list

E get(int index)

Removes and returns the element at the specified index. Elements to the right of position index have 1 subtracted from their indices. Size of list is decreased by 1

E remove (int index)

Create a method that replaces item at specified index in the list with specified element, Returns the element that was previously at index. If the specified element is not of the E, throws a runtime exception

E set (int index, E element)

True or False System.out.print(arr); //This program will output the elements of arr, nicely formatted in square brackets with elements separated by commas.

False (***printing an array is more difficult than an array list. Thus, you would have to create an explicit piece of code that accesses and prints each element as needed).

Int[] coins = new int [4]; Coins[0]=1; Coins[1]=5; Coins[2]=10; Coins[3]=25 ///Rewrite the above program using an initializer list

Int coins ={1,5,10,25}; (***note that this construction is the one case where "new" is not required to create an array)

In a constructor, an empty constructor indicates that what values will be assigned?

The Default Values

public Candy (string na, int cal, boolean sour) In this constructor header, what variable characteristics are being declared???

The name of the candy, its calories, and whether or not the candy Is sour.

True or False System.out.print(list); // this program will output the elements of list, nicely formatted in square brackets, with the elements separated by commas.

True

True or False? Elements of the actual array can be accessed and modidfied

True

True or false? Every parameter is enclosed in parenthesis ().

True

If we have a method call, The call of the method contains ______ __________.

actual parameters

This is the automatic wrapping of primitive types in their wrapper class.

autoboxing

Create a method that Appends obj to the end of the list. Always returns true. If the specified element is not of type E, throws a run-time exception

boolean add(E obj)

In the Method Actual Parameters below, 1. what is the name of the array list we are searching through? 2. What is the name of the candy we are looking for? System.out.println(linearSearch(candyJar, "Hershey"));

candyJar, Hershey

Actual parameters are values to be assigned to the _____ __________ when the method is invoked.

formal parameters

Parameters in the constructor header are ______ __________ and are the first, local variable of the constructor method.

formal parameters

Parameters in the method header are ______ _________ and are the first, local variable of the method

formal parameters.

There are two types of parameters in Java: ______ and ______

formal, actual

//Make an array list for the seven days of the week

import java.util.ArrayList; ArrayList<string>arrayofDays = new ArrayList<string>(7);

Small arrays whose values are known can be declared with a(n)...

initializer list

Create a method that returns the number of elements in the list

int size( )

The Method Formal Parameter is given below: public static boolean linearSearch (arrayList<Candy> candy jar, string search) 1. What is the name of the method? 2. what is the type of method 3. What is the array we want to search over? 4. What word are you searching for in the array list

linear search, boolean, candyJar, search

Every parameter is enclosed in ___________.

parenthesis

An array list provides an alternative way of storing a list of objects and has the following advantages over an array: For example, an Arraylist can ______ and ____ as needed in a program, whereas an array has a fixed length that Is set when the array is created. In an ArrayList list, the last slot is always list.size( )-1, whereas in a partially filled array, you, the programmer, must keep track of the last slot currently is use. For an ArrayList, you can do _________ or ________ with just a single statement. Any shifting of elements is handled _____________. In an array, however, _________ or ________ requires you to write the code that shifts the elements. It is easier to print the element of an ________ than those of an __________.

shrink, grow, insertion, deletion, automatically, insertion, deletion, ArrayList, Array

To ________ an ArrayList means to access all of the elements of the list using an iteration statement (for loop, while loop, or enhanced for loop_

traverse

True or false? An ArrayList can't contain a primitive type like double or int: It must only contain objects (or the references to objects).

true

This is the automatic conversion of a wrapper class to its corresponding primitive type.

unboxing

Create a method that inserts element at specified index. Elements from position index and higher have 1 added to their indices. Size of list is incremented by 1.

void add(int index, E element)


Kaugnay na mga set ng pag-aaral

MIS Cyber security Ch. 9, 10, 11 Exam

View Set

advanced investments exam2 review

View Set

Laboratory Review 3- Chemical Composition of Cells

View Set