Please try the following short pretest. We donβt expect you to know the answers to these questions at all yet! So donβt worry about it if you donβt know the answers. It is fine to pick the βI donβt knowβ answer option. You will take the same test at the end of the PD and see the answers after that. We hope that everyone will see a big improvement!
I. In line 1, print should be changed to println.
II. In lines 1, 2, and 3, print should be capitalized.
III. In lines 1, 2, and 3, the text inside the parentheses should be in quotation marks.
LO 1.4.A Develop code for assignment statements with expressions and determine the value that is stored in the variable as a result of these statements.
public class Party
{
private int numInvited;
private boolean partyCancelled;
public Party()
{
numInvited = 1;
partyCancelled = false;
}
public Party(int invites)
{
numInvited = invites;
partyCancelled = false;
}
}
Which of the following code segments, when placed in a method in a class other than the Party class, correctly creates a new object of the Party class with 20 people invited?
int a = 100;
int b = 90;
if (a >= 100)
{
if (b > 100)
{
System.out.print("go ");
}
else if (b > 90)
{
System.out.print("it ");
}
else
{
System.out.print("up ");
}
}
System.out.print("on ");
What is printed when the code segment above is executed?
Complete the loop below by filling in the missing code. The loop should calculate the number of leap years between the variables year1 and year2, inclusive, using a helper method isLeapYear(year) which returns true if year is a leap year and false otherwise.
public static String changeStr(String str)
{
String result = "";
for (int i = 1; i < str.length() - 1; i += 2)
{
result += str.substring(i, i + 1);
}
return result;
}
What value is returned as a result of the method call changeStr(βABCDEβ)?
Which of the following replacements for the missing code is the most appropriate implementation of a class Cat which contains attributes for the catβs name and age and a constructor?
LO 3.5.A Develop code to define behaviors of an object through methods written in a class using primitive values and determine the result of calling these methods.
LO 3.5.A Develop code to define behaviors of an object through methods written in a class using primitive values and determine the result of calling these methods.
I. int i = 0;
while (i < array.length)
{
array[i] *= 2;
}
II. for (int i = 0; i < array.length; i++)
{
array[i] *= 2;
}
III. for (int i = 1; i <= array.length; i++)
{
array[i] *= 2;
}
LO 4.5.A Develop code for standard and original algorithms for a particular context or specification that involves arrays and determine the result of these algorithms.