Recommendation: Play the game and attempt to answer the questions yourself without looking at the...
-
date post
21-Dec-2015 -
Category
Documents
-
view
220 -
download
2
Transcript of Recommendation: Play the game and attempt to answer the questions yourself without looking at the...
![Page 1: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/1.jpg)
Choose a category. You will be given the answer.
You must give the correct question. Click to begin.
![Page 2: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/2.jpg)
Click here for Final Jeopardy
![Page 3: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/3.jpg)
DataStructures
Jolly Java
CraftyCoding
10 Point
20 Points
30 Points
40 Points
50 Points
10 Point 10 Point 10 Point 10 Point
20 Points 20 Points 20 Points 20 Points
30 Points
40 Points
50 Points
30 Points 30 Points 30 Points
40 Points 40 Points 40 Points
50 Points 50 Points 50 Points
Typing & Hierarchy
OminousOCaml
![Page 4: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/4.jpg)
Write in Java:
let x: int ref = ref 1
![Page 5: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/5.jpg)
int x = 1;
![Page 6: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/6.jpg)
Write in Java:
let y (x: int): int =
x * x + 1
![Page 7: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/7.jpg)
int y(int x) {
return x * x + 1;
}
![Page 8: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/8.jpg)
Write in Java:
map
[3; 1; 2]
fun x -> x + 1
![Page 9: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/9.jpg)
int[] a = [3, 1, 2];
for (int j = 0;
j < a.length; j++) {
a[j]++;
}
![Page 10: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/10.jpg)
Write in Java:let new_counter ():
(unit -> unit * unit -> int) =
let x: int ref = ref 0 in
(fun () -> x := !x + 1, fun () -> !x)
![Page 11: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/11.jpg)
public class Counter {
private int x;
public Counter() { x = 0; }
public void increment() { x++; }
public int get() { return x; }
}
![Page 12: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/12.jpg)
Write in Java:type 'a tree =
| Empty
| Node of 'a tree * 'a * 'a tree
![Page 13: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/13.jpg)
class Node<E> {
// use null for empty tree
public Node<E> left, right;
public E element;
}
![Page 14: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/14.jpg)
Give an example of data that can be
modeled as('a, 'b set) map
![Page 15: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/15.jpg)
A classroom of students, each with
a set of grades.
![Page 16: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/16.jpg)
Give an example of data that can be
modeled asList<Map<E, F>>
![Page 17: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/17.jpg)
A bookshelf of phone books.
![Page 18: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/18.jpg)
What is the main difference between OCaml and Java data structures?
![Page 19: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/19.jpg)
Mutability.
![Page 20: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/20.jpg)
What is one implementation strategy for the
map ADT?
![Page 21: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/21.jpg)
A set of key-value pairs, or a BST
with no repeated elements and a key for each element.
![Page 22: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/22.jpg)
What are two implementation
strategies for the set ADT?
![Page 23: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/23.jpg)
A list with no repeats, a BST
with no repeats, or a map with dummy
keys.
![Page 24: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/24.jpg)
What are the static and dynamic types of x in the following?
Iterator<String> x = new Scanner();
![Page 25: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/25.jpg)
Static type: Iterator<String>
Dynamic type: Scanner
![Page 26: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/26.jpg)
Name two major differences between
interfaces and abstract classes.
![Page 27: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/27.jpg)
1. A class can extend one class but implement many interfaces.
2. An interface cannot contain implementation code; an abstract class can.
![Page 28: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/28.jpg)
What is dynamic dispatch? How does
it work in the abstract machine
model?
![Page 29: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/29.jpg)
Dynamic dispatch: what code (e.g. method body) is executed depends on the dynamic type of the object.
Type found by “pointer chasing” in the abstract model to determine the dynamic type.
![Page 30: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/30.jpg)
List<C> l = new LinkedList<C>();l.add(new A());l.add(new B());D d = l.get(0);
Draw an inheritance tree for classes A, B, C, and D.
![Page 31: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/31.jpg)
D
C
B A
![Page 32: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/32.jpg)
List<String> i = new ArrayList<String>();ArrayList<String> j = new ArrayList<String>();List<Object> k;
For each, state whether valid. Assume they run independently.
i = j;j = i;k = i;k = j;
![Page 33: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/33.jpg)
i = j; // Okayj = i; // Badk = i; // Badk = j; // Bad
![Page 34: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/34.jpg)
What is a parent of all classes? Name
two of its methods.
![Page 35: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/35.jpg)
ObjectString toString();boolean equals(Object o);
(among others)
![Page 36: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/36.jpg)
What is the difference between overriding and
overloading? Which uses dynamic type, and which
uses static type?
![Page 37: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/37.jpg)
Overriding: redefining a method in a child class (same signature). Dynamic type.
Overload: methods with same name, but different arguments. Static type.
![Page 38: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/38.jpg)
What does protected
keyword mean?
![Page 39: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/39.jpg)
Denotes a field that only the class and its subclasses can
access.
![Page 40: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/40.jpg)
Describe two classes in the I/O library, explain what operations you could perform with it.
Describe two different exceptions that may be thrown.
![Page 41: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/41.jpg)
File – can open, create, delete files. Can throw FileNotFoundException.
Reader – (abstract class) allows you to read characters from a stream. Can throw IOExceptions (of which there are many flavors).
![Page 42: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/42.jpg)
Name three different uses of the static keyword in
Java; explain the effect on each kind of entity.
![Page 43: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/43.jpg)
• Classes: static nested classes can be accessed without enclosing instance, e.g. new Outer.Inner(); instead of (new Outer()).Inner();
• Methods: static methods belong to the class, e.g. Math.cos(80);
• Variables: static methods belong to the class, and are shared by all instances.
![Page 44: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/44.jpg)
Complete the method:
// Returns twice the number if odd,// else the number if even.
int foo(int x);
![Page 45: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/45.jpg)
int foo(int x) { if (x % 2 == 0) // even return x; else return x * 2;}
![Page 46: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/46.jpg)
Design classes/interfaces for the situation:
You are writing a Blackboard-alternative software for a class. The software has a dropbox for students to submit assignments (each assignment is either a text document, a code ZIP, or an image diagram). Assignments are identified by a numerical ID.
The professor wants to be able to:- access all documents submitted for a given assignment, in the order they were submitted- assign a grade to each assignment
![Page 47: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/47.jpg)
Sample, this has no fixed solution!
interface Assignment { int getGrade(); void assignGrade(int x); File getFile();}
class Text extends Assignment …class Code extends Assignment…class Diagram extends Assignment…
class DropBox { List<Assignment> getFilesForAssignment(int assignment_id);}
![Page 48: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/48.jpg)
Complete the method:
// Returns the number, // or 0 if not a numerical string. // You should use Integer.parseInt
int getIntFrom(String s);
![Page 49: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/49.jpg)
int getIntFrom(String s) { int x = 0; try {
x = Integer.parseInt(s); } catch (NumberFormatEx..) { // Leave x = 0. } return 0;}
![Page 50: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/50.jpg)
Complete the method:
// Recursive method that returns// true if string is palindrome.
boolean isPalindrome(String s);
![Page 51: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/51.jpg)
boolean isPalindrome(String s) { if (s.length() <= 1) return true;
if (s.charAt(0) == s.charAt(s.length()-1)) { String tmp = s.substring(1, s.length()-1); return isPalindrome(tmp); } else { return false; }}
![Page 52: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/52.jpg)
Complete the method:
// Reverse array in place.void reverseArray(Object[] o);
![Page 53: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/53.jpg)
void reverseArray(Object[] o) { for (int i = 0; i < o.length/2; i++) { Object tmp = o[i]; o[i] = o[o.length-i-1]; o[o.length-i-1] = tmp; }}
![Page 54: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/54.jpg)
Make your wager
![Page 55: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/55.jpg)
At the beginning of the year, we prescribed a design process to
translate informal specifications into code. What
are the four steps of the “design process”?
![Page 56: Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.](https://reader036.fdocuments.in/reader036/viewer/2022062421/56649d565503460f94a34c91/html5/thumbnails/56.jpg)
1. Understand the problem.
2. Formalize the interface.
3. Write test cases.
4. Implement required behavior.