ws ia convert each binary number to its decimal equivalent · pdf filews ia convert each...
TRANSCRIPT
WS IA
Convert each binary number to its decimal equivalent:
1) 1001 2) 1101 3) 1001001 4) 111011
Convert each decimal number to its binary equivalent:
5) 13 6) 31 7) 33 8) 511
Convert each hexadecimal number to its decimal equivalent:
9) A3 10) 12 11) 3F 12) 2B2
Convert each decimal number to its octal equivalent:
13) 222 14) 16 15) 63 16) 513
17) Convert the octal number 147 to hexadecimal
18) Convert the hexadecimal number 4C9 to octal
19) Convert the hexadecimal number E5 to binary
20) Consider the number 344231. What is the smallest base that this can represent?
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
WS IB
1) How many items can be represented by 8 bits?
2) A professional soccer team’s depth chart is allowed to represent up to 40 players. How
many bits are needed to represent a given team’s roster?
3) How many bits are there in 10 KB?
4) how many bits are there in 3 MB?
5) A picture is comprised of 350 possible colors. How many bits are needed to store each
pixel?
6) How many items can be represented by 3 bytes?
Write the decimal number 311 in each of the provided bases:
7) Binary 8) Octal 9) Hexadecimal 10) Base-20
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 2 3 4 5
6 7 8 9 10
WS IC
Choices: (Circle the correct answers)
2048 128 1024 1A5 24
3 2^48 15 8224 10
1A5 201 26 247 12
2^128 439 2^16 37 45
1) Number of items that can be represented by 16 bytes.
2) Binary number 100101 in decimal.
3) Number of items that can be represented by 10 bits.
4) Hexadecimal number 1B7 in decimal.
5) A colour is made up of White, Blue, Yellow, and Red elements, with each of those
having 8 tonal values. The # of bits needed to represent a pixel of this colour.
6) Octal number 354 in base-11.
WS ID
Convert each binary number to its decimal equivalent:
1) 11111 2) 1011 3) 1011001 4) 1000001
Convert each decimal number to its binary equivalent:
5) 33 6) 113 7) 1 8) 222
Convert each hexadecimal number to its decimal equivalent:
9) B4 10) 10C 11) 3D 12) 2A0
Convert each decimal number to its octal equivalent:
13) 1011 14) 24 15) 65 16) 113
17) Convert the octal number 125 to hexadecimal
18) Convert the hexadecimal number 1F8 to octal
19) Consider the number 2433. Would it have a higher value as a base-5 number, or a base-6
number?
20) If C3P0 were a number rather than a droid what is the smallest base that this can be?
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
WS IIA
Write code that would output each of the following:
1) You are “Awesome”
2) Walshy is
my idol
3) I’m \James/ Walsh
4) This is how you make a
quotation: \”
Convert each decimal number to its binary equivalent:
5) 33 6) 63 7) 100
Convert each decimal number to its hexadecimal equivalent:
8) 33 9) 63 10) 100
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1) System.out.print(“ “);
2) System.out.print(“ “);
3) System.out.print(“ “);
4) System.out.print(“ “);
5 6 7
8 9 10
WS IIB
Convert each binary number to its decimal equivalent:
1) 1010101 2) 101010 3) 1001001 4) 11110
Convert each decimal number to its binary equivalent:
5) 37 6) 127 7) 2 8) 513
Convert each hexadecimal number to its decimal equivalent:
9) B14 10) 1C 11) 3AD 12) 2E0
Convert each decimal number to its octal equivalent:
13) 101 14) 25 15) 63 16) 515
17) Convert the octal number 64 to hexadecimal
18) Convert the hexadecimal number 1AA to octal
19) Convert the hexadecimal number C7 to binary
20) What is the smallest base that would need the letter J to help represent it?
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
WS IIC
Write code that would output each of the following:
1) You are “\\Awesome//”
2) This class is
“fun”
3) it is at: C://HappyFolder
4) This is how you make a
backslash: \\
Convert each decimal number to its binary equivalent:
5) 53 6) 111 7) 9
Convert each decimal number to its hexadecimal equivalent:
8) 53 9) 111 10) 9
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1) System.out.print(“ “);
2) System.out.print(“ “);
3) System.out.print(“ “);
4) System.out.print(“ “);
5 6 7
8 9 10
WS IID
Convert each binary number to its decimal equivalent:
1) 10010 2) 10111 3) 10001 4) 1111
Convert each decimal number to its binary equivalent:
5) 88 6) 12 7) 0 8) 131
Convert each hexadecimal number to its decimal equivalent:
9) B12 10) CC 11) AD 12) 333
Convert each decimal number to its octal equivalent:
13) 1001 14) 125 15) 65 16) 8
17) Convert the octal number 15 to hexadecimal
18) Convert the hexadecimal number AA to octal
19) Convert the hexadecimal number B7 to binary
20) What is the smallest base that would need the letter C to help represent it?
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
WS IIIA
For each x is 5, y is 2, and z is 3. Provide each variable's value after:
1) x *= y++ / --z; 2) x %= ++y--;
Find the value of in a, if:
3) a = 11 / 3 * 2 + 3 % 2 4) a = (3 % 7) % (9 % 14)
Convert each value:
5) The octal value 374 to decimal.
6) The decimal number 46 to base 3.
7) The binary number 100101 to octal.
Evaluate each expression:
8) 3.0 / 5; 9) (double) 2 / 5; 10) 4 / (double) 5;
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1) x = y = z = 6)
2) x = y = z = 7)
3) a = 8)
4) a = 9)
5) 10)
WS IIIB
For each series of numerical arguments, rewrite the expression with parentheses (if
needed) so that the expression evaluates to the bracketed value. (Superfluous
parentheses will be considered incorrect.
1) [ -3 ] 3 + 4 / 2 - 6 2) [ 40 ] 30 / 6 * 5 + 3
3) [ 9 ] 15./ 4 * 3 4) [ 7 ] 13 % 6 * 2 + 5
5) [ 7 ] 32 / 2 + 5 + 3
At the beginning of each question, the values of x, y , and z are initialized to 4, 3, and 5
respectively. Determine the final values of each:
6) x = ++y; 7) x = y++;
8) y += ++x; 9) y += x--;
10) z += ++x * y--;
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1) 6) x = y = z =
2) 7) x = y = z =
3) 8) x = y = z =
4) 9) x = y = z =
5) 10) x = y = z =
WS IIIC
Evaluate the int variable num1 for each expression:
1) num1 = 3 + 15 % 7;
2) num1 = 2 * 3 % 10;
3) num1 = 15 - 3 * 2;
4) num1 = 15 % 3 * 22;
5) num1 = 17 / 5 + 2;
6) num1 = 18 / 3 * 2;
7) num1 = 2 / 3 + 2 / 3 + 2 / 3;
For each question the values of x, y, and z are initialized to be 5, 3, and -2 respectively.
Give the final values of each for each question.
8) x = y * z++; 9) x += --y + z--; 10) y %= ++x + z--;
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6
2 7
3 8 x = y = z =
4 9 x = y = z =
5 10 x = y = z =
WS IIID
Describe or list the potential numbers that could be returned by each call of nextInt.
The import of the Random class, and the line of code: Random r = new Random();
both exist.
1) r.nextInt(14) + 2; 2) r.nextInt(1) - 13;
3) r.nextInt(13) - 6; 4) 3 * (r.nextInt(5) + 4);
5) (r.nextInt(6) + 3) / 2;
For each described range, provide the call to nextInt on object r that would result in that range: ( remember “[“ denotes inclusive whereas “(“ denotes exclusive )
6) [7, 14] 7) [-3, 8)
8) [2, 16] evens 9) [15, 50] multiples of 5
10) 10 or 20 only
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6
2 7
3 8
4 9
5 10
WS IVA
Fill in the following values onto the blanks for variables x and y. Then answer what
would be the final value of z in each scenario:
1) 2, 2 4) 5, 5 7) 4, 1
2) 1, 2 5) 3, 7 8) 6, 6
3) 7, 7 6) -3, 2 9) 1, 1
int x = ___, y = ___, z = 0;
if(x < 3&& y != 2 || x <=5 && y == x)
if(x==4)
z = 1;
else if(x % 5 == 1)
z = 2;
else if(y * 3 / 5 == 4)
z = 3;
else
z = 4;
else
if(y == 2 && x != 1)
z = 6;
else if(x * 5 == 5)
z = y + 7;
else
z = x + y;
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 4 7
2 5 8
3 6 9
WS IVB
Fill in the truth table for the following expressions:
Expression #1: A && B || !A && !B
Expression #2: A == B
A Value B Value Exp #1 Result Exp #2 Result
T T
T F
F T
F F
Fill in the truth table for the following expression:
!A && (B || !C) || A == C
A Value B Value C Value Resultant Value
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F
WS IVC
Fill in the truth table for the following expressions:
Expression #1: A && !B || !A && B
Expression #2: A != B
A Value B Value Exp #1 Result Exp #2 Result
T T
T F
F T
F F
Fill in the truth table for the following expression:
!(A && !B) || !(B || C)
A Value B Value C Value Resultant Value
T T T
T T F
T F T
T F F
F T T
F T F
F F T
F F F
WS IVD
Random rand = new Random(); For each question, list or describe the potential range.
1) rand.nextInt(5) + 2; 2) 2 * rand.nextInt(3) + 4;
3) (2 * rand.nextInt(3)) + 4; 4) (2 * nextInt(5) + 3) * 2;
Write each of the following numbers from the given base in decimal:
5) 344 (octal) 6) 100110 (binary) 7) 1B4 (Hex)
8) 212 (base-3) 9) 4113 (base-5) 10) 1AB (base-14)
For each situation, give the number of bits:
11) 2MB 12) 5 KB
13) What it would take to represent 240 items.
14) What it would take to represent 2050 items
15) 10 Bytes + 5 Bytes
Answers:
__________________________________________________________________________
1 6 11
2 7 12
3 8 13
4 9 14
5 10 15
WS VA
1) /* @return the sum of @param one, @param two, and @param three */
public static int sum3(int one, int two, int three)
{
}
2) /* @return the units digit of @param bigNum. If @param bigNum was 3752, the return
* would be 2 */
public static int unitsDigit(int bigNum)
{
}
3) /* @return true if @param var1 is greater than @param var2 */
public static boolean firstIsBigger(double var1, double var2)
{
}
WS VB
For each method header, identify the name, parameter type(s), and return type:
1) public int doIt(double d)
2) public double yeah()
3) public void doItAgain(double d, int i)
4) public boolean isHappy()
5) public int doIfTrue(boolean b)
6) public void doItAgain()
7) public char whichLet(String sent, int which)
8) public void maybePrint(boolean b, int n)
Number Name Return type Parameter type(s)
1
2
3
4
5
6
7
8
WS VC
Assume that each of the following variables are available for each method: int i; double d; char c; boolean b; String s; Decide which variable (if any) should be returned in each. 1) public static String one(int num) { return ____; } 2) public static char two(double dec, String str) { return ___; } 3) public static double three(int num, boolean boo) { return ___; } 4) public static char four() { return ___; } 5) public static String five(boolean isCool) { return ___; } 6) public static void six(char let, String name) { return ___; } 7) public static double seven(double dec, String lastName) { return ___; } 8) public static void eight(boolean isANum) { return ___; } 9) public static String nine(char symbol) { return ___; } 10) public static int ten(int num1, double num2) { return ___; } Answers: __________________________________________________________________________
1 6
2 7
3 8
4 9
5 10
WS VD
Write a method header for each of the following:
1) hypoteneuse returns a double and takes two doubles (leg1 and leg2) as parameters
2) largest takes three integers (one, two, and three) as parameters, and returns an int
3) menu takes a char named choice and String named selection as parameters, and returns
nothing
4) firstFive which has a return value of type String and takes no parameters
5 a and b) Overloaded methods secondMenu which returns a String value, and takes either a
char and a String, or two Strings as parameters
Answers:
__________________________________________________________________________
1
2
3
4
5a
5b
WS VIA
For each expression, state the value of ans and the type of variable ans would have to be
in order to compile correctly:
String str = "Boy, that Walshy sure is cool!";
1) ans = str.substring(2, 6);
2) ans = str.lastIndexOf('s');
3) ans = str.indexOf("hat");
4) ans = str.charAt(str.length() - 1);
5) ans = str.charAt(str.indexOf('o', 2) - 1);
6) ans = str.substring(3, 4) + str.substring(str.indexOf('h'));
7) ans = str.indexOf('w');
8) ans = str.substring(0, 3).equals("boy");
9) ans = str.substring(str.indexOf(' ')).toLowerCase();
10) ans = str.substring(str.indexOf('W'), str.indexOf('h') + 1) + " = " +
str.substring(str.lastIndexOf(' '));
Answers:
__________________________________________________________________________
Type Value
1
2
3
4
5
6
7
8
9
10
WS VIB
State whether or not the two expressions are equivalent (A, B, and C represent boolean
values):
1) !A || B / !(A && !B) 2) A && B || A && !B / A && B == B
3) A == B && A == C / !A && !B && !C 4) !(!A && !B) / A || B
5) B && !A || A && !B / !(A && B) 6) !(A && !B) / A != B
String a = "Hello there"; String b = "I cast my lot";
What is the value of:
7) a.substring(a.indexOf(' ')); 8) b.charAt(a.indexOf('e', a.indexOf('e')+1));
9) b.substring(7, 9) + a.substring(6); 10) a.substring(3,7).equals(b.substring(10));
Answers:
__________________________________________________________________________
1 4
2 5
3 6
7
8
9
10
WS VIC
String a = "Magnificence and excellence";
String b = "Synonyms for Walsh";
int lenA = a.length();
int lenB = b.length();
What is the value of each expression?
1) a.charAt(lenB); 2) b.charAt(lenA); 3) a.charAt(lenA-lenB);
4) b.charAt(lenA % lenB); 5) a.substring(lenA-lenB, lenB);
6) b.substring(lenA-lenB, lenB); 7) a.substring(lenB % 2, lenB/2);
8)b.substring(lenA % 2, lenA/2); 9) a.charAt(b.lastIndexOf('y'));
10) a.charAt(b.indexOf(a.charAt(lenB % b.indexOf('o')).toLowerCase())));
Answers:
__________________________________________________________________________
1
2
3
4
5
6
7
8
9
10
WS VID
1) /* @return ten times the smaller of @param num1, and @param num2 */
public static int tenTimes(int num1, int num2)
{
}
2) /* If there is more than one word in @param sent, @return the last word.
* If there is only one word, @return @param sent */
public static String lastWord(String sent)
{
}
3) /* @return the true average of @param a, b, and c */
public static double avg(int a, int b, int c)
{
}
4) /* @return true if there is more than one occurrence of @param let
* in @param sent */
public static boolean numOccurs(String sent, char let)
{
}
WS VIIA
1) /* @return true if @param a, b, and c all occur in @param str */ public static boolean containsAll(String str, char a, char b, char c) { } 2) /* @return the letter in @param word that is alphabetically last * precondition: @param word is a single word comprised of all lowercase letters */ public static char laterLetter(String word) { } 3) /* @return the first and last words in @param sent, concatenated * If there is only one word, return it*/ public static String firstAndLast(String sent) { } 4) /* @return the number of lowercase vowels in @param word */ public static int vowels(String word) { }
WS VIIB
For each example, state the final value of x:
1) int x = 1, y = 0; 2) int x = 0, y = 1
while(y < 5) while(y < 10)
{ x *= 2; {
y++; x += y++;
} }
3) int x = 5, y = 2; 4) int x = 3, y = 4, z = 5;
do do
{ x *= y; {
x--; x = y + z--;
}while(x < 10); }while(x>9);
5) int x = 3; 6) int x = 5;
for(int a = 0; a < 8; a +=2) for(int b = 0; b < 2 * x; b++)
{ {
x *= 2; x--;
} }
Answers:
__________________________________________________________________________
1 4
2 5
3 6
WS VIIC
1) /* @return true if @param a, b, or c occur in @param str */ public static boolean containsAny(String str, char a, char b, char c) { } 2) /* @return any character that is in both @param word1 and @param word2 * if there are no similar characters, @return ‘_’ */ public static char sameLetter(String word1, String word2) { } 3) /* @return true if @param num2 is a multiple of @param num1 * precondition: both parameters are natural integers */ public static boolean multiple(int num1, int num2) { } 4) //* @return true if @param num1 is a factor of @param num2 * precondition: both parameters are natural integers */ public static boolean factor(int num1, int num2) { }
WS VIID
For each example, state the final value of x, or answer: “infinite loop”:
1) int x = 0, y = 1; 2) int x = 0, y = 1
while(y < 5) while(y < 10)
{ x *= 155; {
y++; x += ++x + y;
} }
3) int x = 5, y = 2; 4) int x = 3, y = 4, z = 5;
do do
{ x *= y--; {
x++; x = y-- + z--;
}while(x < 10); }while(x>9);
5) int x = 3; 6) int x = 5;
for(int a = 0; a < 8; a +=2) for( ; x < 10; x +=2)
{ {
x *= a; x--;
} }
Answers:
__________________________________________________________________________
1 4
2 5
3 6
WS VIIIA
int[] a = {3, 5, 7, 9, 11, 13, 15};
int[] b = {1, 4, 7, 10, 13};
What is the value of each expression?
1) a.length - b.length; 2) a[4] + b[2];
3) a[b.length]; 4) b[a.length];
5) a[b[1]]; 6) b[b[0]];
7) a + b;
For each question, x is initialized to the value 1. What is the final value of x for each?
8) for(int i = 0; i < a.length; i++)
x += a[i];
9) for(int i = 0; i < b.length; i++)
x += b[i];
10) for(int i = 0; i < b.length; i++)
x += a[i] + b[i];
Answers:
__________________________________________________________________________
1 6
2 7
3 8
4 9
5 10
WS VIIIB
1) /* @return the last element in @parm numbers*/ public static int lastNum(int[] numbers) { } 2) /* @return true if @param target is contained in @param paragraph */ public static boolean isInThere(String[] paragraph, String target) { } 3) /* @return half the sum of all of the elements in @param nums */ public static int halfSum(int[] nums) { } 4) //* @return an array that has of the same elements as @param strng, but in reverse order */ public static char[] rev(char[] strng) { }
WS VIIIC
1) /* @return the middle element in @parm numbers*/ public static int midNum(int[] numbers) { } 2) /* @return the total number of ‘A’s contained in @param paragraph */ public static int howManyAs(String[] paragraph) { } 3) /* print every third element in @param nums */ public static void everyThree(int[] nums) { } 4) /* @return an array that has only the first five elements of @param words * precondition: @param words.length > 4 */ public static String[] firstFive(String[] words) { }
WS VIIID
1) /* @return the sum of the first and last elements in @parm numbers*/ public static int fAndLNums(int[] numbers) { } 2) /* @return the number of Strings in @param palabras that have more than one word */ public static int numNonSolos(String[ ] palabras) { } 3) /* print every fourth element of @param words */ public static void evFour(String[] words) { } 4) /* @return true if any element of @param nums is divisible by 11 */ public static boolean isdivByLev(int[] nums) { }
WS IXA
For each question, assume that 2-D array grid has been instantiated with a size and appropriate type: 1) for(int r = 0; r < grid.length; r++) 2) for(int r = 0; r < grid.length; r++) { for(int c = 0; c < grid[r].length; c++) { for(int c = 0; c < grid[r].length; c++) { grid[r][c] = r * c; { grid[r][c] = r * r; } } } } 3) for(int r = 0; r < grid.length; r++) 4) for(int r = 0; r < grid.length; r++) { for(int c = 0; c < grid[r].length; c++) { for(int c = 0; c < grid[r].length; c++) { if( r < c) { if( r == c) grid[r][c] = ‘A’; grid[r][c] = r + c; else if (r == c) else if( r > c) grid[r][c] = ‘B’; grid[r][c] = r * c; else else grid[r][c] = ‘C’; grid[r][c] = c - r; } } } } Answers:
__________________________________________________________________________
1) 2)
3) 4)
WS IXB
For each question, assume that 2-D array grid has been instantiated with a size and appropriate type: 1) for(int r = 0; r < grid.length; r++) 2) for(int r = 0; r < grid.length; r++) { for(int c = 0; c < grid[r].length; c++) { for(int c = 0; c < grid[r].length; c++) { grid[r][c] = r * 2; { grid[r][c] = c * c; } } } } 3) for(int r = 0; r < grid.length; r++) 4) for(int r = 0; r < grid.length; r++) { for(int c = 0; c < grid[r].length; c++) { for(int c = 0; c < grid[r].length; c++) { if( r % 2 == 0) { if( (r + c) % 2 == 0) grid[r][c] = ‘A’; grid[r][c] = ‘D’; else if (c % 3 == 1) else if( (r * c) % 2 == 0) grid[r][c] = ‘B’; grid[r][c] = ‘E’; else else grid[r][c] = ‘C’; grid[r][c] = ‘F’; } } } } Answers:
__________________________________________________________________________
1) 2)
3) 4)
WS IXC
1) /* @return the sum of the elements in the odd columns of @param numbers */ public static int colSum(int[][] numbers) { } 2) * @return the sum of the elements in the odd rows of @param nums */ public static int rowSum(int[][] nums) { } 3) /* @return true if any element of @param words has more than 10 characters */ public static boolean hasLongString(String[][] words) { } 4) /* @return the row in @param nums that has the highest sum */ public static int[] bigRow(int[][] nums) { }
WS IXD
1) /* @return the true average of all of the elements in @param numbers */ public static double twoDAvg(int[][] numbers) { } 2) /* changes the value of all negative elements in @param vals to 0 */ public static void noMoNegs(int[][] vals) { } 3) /* @return a String that is all of the elements of @param lets */ public static String strngMaker(char[][] lets) { } 4) /* @return a 2-D array that has all of the elements of @param nums * precondidiont: nums.length is a perfect square * postcondition: the 2-D array has the same number of rows as columns */ public static int[][] bigRow(int[] nums) { }
WS XA
1) /* @return the true average of all of the elements in @param numbers */ public static double numAvg(int[] numbers) { } 2) /* @return the true average of all of the elements in @param numbers */ public static double twoDAvg(int[][] numbers) { } 3) /* @return the true average of all of the elements in @param numbers */ public static double numListAvg(ArrayList<Integer> numbers) { } 4) /* @return an ArrayList that has all of the same elements of @param nums in the same order */ public static ArrayList<Integer> converter(int[] nums) { }
WS XB
1) /* @return the value of the largest element in @param nums */ public static int bigNum(ArrayList<Integer> nums) { } 2) /* eliminates all negative elements from @param nums */ public static void noMoNegs(ArrayList<Integer> nums) { } 3) /* @return an ArrayList that is all of the elements form @param names that begin with ‘W’ */ public static ArrayList<String> dubNames(ArrayList<String> names) { } 4) /* @return an ArrayList that has all of the same elements of @param nums * in row dominant order */ public static ArrayList<Integer> converter(int[][] nums) { }
WS XC
Use the following 2-D array called numGrid to answer each question:
5 -4 22 3 5 -20
7 1 3 15 55 11
12 13 16 -12 2 8
1) int total = 0; 2) int total = 0; for(int[] rows: numGrid) for(int[] rows: numGrid) { for(int el: rows) { for(int el: rows) { if(el > 12) { if(el > 13) total += 1; total += el; } } } } What is the value of total? What is the value of total? 3) int total = 0; 4) int total = 0; for(int r = 0; r < numGrid.length; r+=2) for(int r = 0; r < numGrid.length; r++) { for(int c =1; c < numGrid[r].length; c+=3) { for(int c = r; c < numGrid[r].length; c++) { { total += el; total += el; } } } } What is the value of total? What is the value of total? Answers:
__________________________________________________________________________
1 2 3 4
WS XD
1) /* @return the index of the largest element in @param nums */ public static int bigNum(ArrayList<Integer> nums) { } 2) /*@return an ArrayList that contains all elements in @param nums * from the first element until the first instance of a 0 */ public static ArrayList<Integer> untilZero(List<Integer> nums) { } 3) /* @return an int[] that represents the number of scores in each grade range * such that [0] is the number of As, [1] is the number of Bs... etc. * all scores are between 0 and 100 inclusive */ public static int[] testRange(ArrayList<Integer> tests) { } 4) /* @return an int[] that has all of the same elements of @param nums */ public static int[] converter(List<Integer> nums) { }
WS XIA
public Interface RandomSelector { public Object select(Object[] collection); } 1) public class TestData implements RandomSelector { private Integer[] scores; // write method select } 2) public class Names implements RandomSelector { private String[]names; // write method select } 3) public class MountainRange implements RandomSelector { private Double[] heights; // write method select } 4) public class classes implements RandomSelector { private ArrayList<Student>[] scores; // write method select } Answers:
__________________________________________________________________________
1) 2) 3) 4)
WS XIB
public Interface Talk public Interface Grow { // code not shown } { // code not shown }
public abstract class Animal public abstract class Intelligence { // code not shown } { // code not shown }
1) Which of the following are acceptable headers? Why? A) public class Cat extends Animal implements talk, implements grow B) public class Cat extends Intelligence implements talk, implements grow C) public class Cat extends Animal, extends Intelligence, implements talk D) public class Cat extends Animal, extends Intelligence, implements talk, implements grow 2) Which of the following are valid declarations? Why? A) Interface Talk = new Talk(); B) Talk t = new Animal(); C) Talk t = new Grow(); D) Talk t = new Talk(); E) Animal a = new Animal(); F) Animal a = new Intelligence(); Convert each number from the given base to the final base: 3) 332; from decimal to octal 4) 12B; from hexadecimal to decimal 5) 1000110; from binary to octal 6) 12021; from base-3 to base-5 For the following questions, String str = “Where we’re going, we don’t need roads. 7) What is the value of: str.length()? 8) What is the value of: str.indexOf(‘w’)? 9) What is the value of: str.substring(1, 8)? 10) What is the value of: str.substring(str.lastIndexOf(“w”)).length()? Answers:
__________________________________________________________________________
1 6
2 7
3 8
4 9
5 10
WS XIC
List<Integer> a contains the following data: {1, 4, 7, 10, 10, 13}
List<Integer> b contains the following data: {1, 2, 4, 7, 11, 16, 22, 29}
What is the value of each expression?
1) a.size() - b.size(); 2) a.get(2) + b.get(3);
3) b.get(a.size(); 4) a.get(b.size() / 2);
5) a,get(b.get(1)); 6) b,get(a.get(2));
7) a - b;
For each question, x is initialized to the value 0. What is the final value of x for each?
8) for(int i = 0; i < a.size(); i++) 10) for(int i = 0; i < a.size(); i++) x += a.get(i); { if(a.get(i) %5 == 2) a.remove(i); 9) for(int i = 0; i < a.size(); i++) } x += b.get(i); for(int j = 0; j < a.size(); j++) { x += a.get(j); } Answers:
__________________________________________________________________________
1 6
2 7
3 8
4 9
5 10
WS XID
Describe or list the potential numbers that could be returned by each call of nextInt.
1) Math.random() * 2; 2) (int) (Math.random() * 2);
3) (int) (Math.random() * 4) + 3; 4) 2 * ((int) (Math.random() * 3) + 4);
5) ((int) (Math.random() * 5) + 4) / 2;
For each described range, provide the call to nextInt on object r that would result in that range: ( remember “[“ denotes inclusive whereas “(“ denotes exclusive )
6) [7, 14] 7) [-3, 8)
8) [2, 16] evens 9) [15, 50] multiples of 5
10) 10 or 20 only
----------------------------------------------------------------------------------------------------------------------------
ANSWERS:
1 6
2 7
3 8
4 9
5 10
WS XIIA public class Name
{ private String first;
private String last;
// write the implementation for the empty constructor
public Name()
{
}
//write the implementation for the other constructor
public Name(String f, String l)
{
}
//mutates P.I.V. first so that only the first letter is uppercase
public void formatFirst()
{
}
//mutates P.I.V. last so that only the first letter is uppercase
public void formatLast()
{ /* you do not have to write this one */ }
//@return true if the formatted version of this first equals the formatted version of @param other’s
public boolean sameFirst(Name other)
{
}
//@return true if the formatted version of this last equals the formatted version of @param other’s
public boolean sameLast(Name other)
{ /* you do not have to write this one */ }
//@return the total number of characters in PIV first and PIV last
public int totalLetters()
{
}
//@return a String in the output formatted last, formatted first… e.g. Walsh, James
public String toString()
{
}
WS XIIB
class Computer, which implements Comparable has three properties: price, hard drive
size, and brand.
There are three constructors for class Computer: one default, one that takes an int,
double, and String
and on=e that only takes a String
There are a get and a set for every property
There is a method called sale, which changes the price of this Computer to reflect a
20% discount.
There is a method called upgrade, which adds 250 GB to the hard drive size
There is a method called isGoodDeal which returns true if this Computer has at least a
500 GB hard drive, costs less than &599.99, and is not a Dell
The toString method should display information about all PIVs and about method
isGoodDeal
WS XIIIA
class Athlete:
class Athlete implements Comparable.
It has 2 properties: name(last name of the player) and number(as in uniform number)
There are 3 constructors: one default, one with a String and an int parameter, and one with only
a parameter for the name.
There are get and set methods for each property.
There is a method called isLongName which returns true if the name is more than 8 characters
long
There is exactly one abstract method called ballType which returns the name of the CIF
required brand of ball
The toString method is overridden to return pertinent information regarding all public information
(including longName and ballType).
class TennisPlayer
class TennisPlayer has an additional property which represents the top service speed (decimals
should be allowed).
There are 2 constructors: one default and one that takes 3 parameters.
There is a get and set method available for every property
There is a method called servesFaster which has a TennisPlayer parameter and returns true if
this serve is faster than the paramter’s serve
The tosTring method should be updated to include information on additional public info
class Tennis player is not abstract!
Write both Athlete and TennisPlayer in their entirety
WS XIIIB
Write the class header for each class:
1) Food:
2) Meat:
3) Vegetables:
4) Steak:
5) Chicken:
6) Green:
7) Lettuce:
8) Spinach:
9)Romaine:
10) RedLEaf:
Food
Meat
<uses the CookTime interface>
Steak <uses the CookTime interface>
Chicken <uses the CookTime interface>
Vegetables
Green
Lettuce
Romaine RedLeaf
Spinach
<uses the Canned interface>
WS XVA
public static int recur1(int x) public static int recur2(int x)
{ {
if(x < 1) if(x < 2)
return 1; return 2;
else else
return recur(x - 2) + x; return recur(x - 2) + (x-1);
}
1) What is the value of recur1(5)? 2) What is the value of recur1(8)?
3) What is the value of recur2(1)? 4) What is the value of recur2(5)?
5) What is the value of recur1(recur2(3))? 6) What is the value of recur2(recur1(4))?
7) How many times would the method recur1 be called with the statement: recur1(5), including
the original call?
8) How many times would the method recur2 be called with the statement: recur1(4), including
the original call?
Answers:
__________________________________________________________________________
1 5
2 6
3 7
4 8
WS XVB
1) /* @return the sum of every third number between 1 and num * MUST be done recursively */ public static int bigNum(ArrayList<Integer> nums) { } 2) /*@return an ArrayList that contains all elements in @param nums * but in reverse order */ public static ArrayList<Integer> revConvert(int[] nums) { } 3) /* @return the number of times that any element from @param subset appears in * @param data */ public static int dataCount(ArrayList<String> data, ArrayList<String> subset) { } 4) /* @return an int[] that has every other element of @param nums */ public static int[] converter(List<Integer> nums) { }
WS XVC
public static int recur1(int x) public static int recur2(int x)
{ {
if(x < 1) if(x < 2)
return 1; return 2;
else else
return recur(x - 3) + x; return recur(x - 2) * (x-3) / 3;
}
1) What is the value of recur1(5)? 2) What is the value of recur1(8)?
3) What is the value of recur2(1)? 4) What is the value of recur2(5)?
5) What is the value of recur1(recur2(3))? 6) What is the value of recur2(recur1(4))?
7) How many times would the method recur1 be called with the statement: recur1(5), including
the original call?
8) How many times would the method recur2 be called with the statement: recur1(4), including
the original call?
Answers:
__________________________________________________________________________
1 5
2 6
3 7
4 8