Itsc 1213 exam 1 & 2 questions and
complete solutions graded A+
If you saw the following in a UML diagram, what does it mean? - my Counter: int - correct
answer ✔✔This is a private int field
If you saw the following in a UML diagram, what would it mean? + Student Record () - correct
answer ✔✔A public constructor
If you saw the following in a UML diagram, what would it mean? + get Record(int) : Student
Record - correct answer ✔✔A public method that takes an int parameter and returns a Student
Record object
What is printed when the following code executes and x has been set to 3 and y has been set to
6? - correct answer ✔✔first case
Given a 2d array arr[][], match items from the left to its corresponding answer on the right. -
correct answer ✔✔The index of the last row --> arr. length-1
The index of the item in the first row and first column. --> arr[0][0]
The index of the item in the first row and second column. --> arr[0][1]
The number of elements in an array. --> arr.length * arr[0].length
A student has created a Party class. The class contains variables to represent the following.
An int variable called numOfPeople to represent the number of people at the party.
A boolean variable called discoLightsOn to represent whether the disco ball is on.
A boolean variable called partyStarted to represent whether the party has started.
,The object myParty is declared as type Party. Which of the following descriptions is accurate? -
correct answer ✔✔myParty is an instance of the Party class.
Which of the following is false about import statements? - correct answer ✔✔you must specify
the class you are importing in the import statement
Which will cause the shortest execution of a binary search looking for a value in an array of
integers? - correct answer ✔✔The value is in the middle of the array
What are some of the reasons you would use an enhanced for-each loop instead of a for loop?
I: If you wish to access every element of an array.
II: If you wish to modify elements of the array.
III: If you wish to refer to elements through a variable name instead of an array index - correct
answer ✔✔I and III only.
Assume that nums in an instance field declared in a class
private ArrayList<Integer> nums;
and it has been created as an ArrayList object and it initially contains the following Integer
values [0, 0, 4, 2, 5, 0, 3, 0]. If the same class has a method called numQuest defined as follows:
// precondition: nums.size() > 0;
// nums contains Integer objects
public void numQuest() {
int k = 0;
Integer zero = new Integer(0);
while (k < nums.size()) {
if (nums.get(k).equals(zero)) nums.remove(k);
k++; }
}
, What will nums contain as a result of executing numQuest? - correct answer ✔✔[0, 4, 2, 5, 3]
What will print when the following code executes?
ArrayList<String> list1 = new ArrayList<String>();
list1.add("Anaya");
list1.add("Layla");
list1.add("Sharrie");
list1.set(1, "Destini");
list1.add(1, "Sarah");
System.out.println(list1);
You can reference this table for a description of some of the ArrayList methods. The E type
refers to the base type of the ArrayList: - correct answer ✔✔"Anaya", "Sarah", "Destini",
"Sharrie"
Given the following Date class
public class Date {
private int year;
private int month;
private int day;
public Date() {
/** Implementation not shown */ }
public Date(int year, int month, int day)
{ /** Implementation not shown */ }
public void print()
{ /** Implementation not shown */ } }
complete solutions graded A+
If you saw the following in a UML diagram, what does it mean? - my Counter: int - correct
answer ✔✔This is a private int field
If you saw the following in a UML diagram, what would it mean? + Student Record () - correct
answer ✔✔A public constructor
If you saw the following in a UML diagram, what would it mean? + get Record(int) : Student
Record - correct answer ✔✔A public method that takes an int parameter and returns a Student
Record object
What is printed when the following code executes and x has been set to 3 and y has been set to
6? - correct answer ✔✔first case
Given a 2d array arr[][], match items from the left to its corresponding answer on the right. -
correct answer ✔✔The index of the last row --> arr. length-1
The index of the item in the first row and first column. --> arr[0][0]
The index of the item in the first row and second column. --> arr[0][1]
The number of elements in an array. --> arr.length * arr[0].length
A student has created a Party class. The class contains variables to represent the following.
An int variable called numOfPeople to represent the number of people at the party.
A boolean variable called discoLightsOn to represent whether the disco ball is on.
A boolean variable called partyStarted to represent whether the party has started.
,The object myParty is declared as type Party. Which of the following descriptions is accurate? -
correct answer ✔✔myParty is an instance of the Party class.
Which of the following is false about import statements? - correct answer ✔✔you must specify
the class you are importing in the import statement
Which will cause the shortest execution of a binary search looking for a value in an array of
integers? - correct answer ✔✔The value is in the middle of the array
What are some of the reasons you would use an enhanced for-each loop instead of a for loop?
I: If you wish to access every element of an array.
II: If you wish to modify elements of the array.
III: If you wish to refer to elements through a variable name instead of an array index - correct
answer ✔✔I and III only.
Assume that nums in an instance field declared in a class
private ArrayList<Integer> nums;
and it has been created as an ArrayList object and it initially contains the following Integer
values [0, 0, 4, 2, 5, 0, 3, 0]. If the same class has a method called numQuest defined as follows:
// precondition: nums.size() > 0;
// nums contains Integer objects
public void numQuest() {
int k = 0;
Integer zero = new Integer(0);
while (k < nums.size()) {
if (nums.get(k).equals(zero)) nums.remove(k);
k++; }
}
, What will nums contain as a result of executing numQuest? - correct answer ✔✔[0, 4, 2, 5, 3]
What will print when the following code executes?
ArrayList<String> list1 = new ArrayList<String>();
list1.add("Anaya");
list1.add("Layla");
list1.add("Sharrie");
list1.set(1, "Destini");
list1.add(1, "Sarah");
System.out.println(list1);
You can reference this table for a description of some of the ArrayList methods. The E type
refers to the base type of the ArrayList: - correct answer ✔✔"Anaya", "Sarah", "Destini",
"Sharrie"
Given the following Date class
public class Date {
private int year;
private int month;
private int day;
public Date() {
/** Implementation not shown */ }
public Date(int year, int month, int day)
{ /** Implementation not shown */ }
public void print()
{ /** Implementation not shown */ } }