Intro CS: Semester1 Exam Review Name: ______

1. What is the difference between a class method and an instance method? Give examples of both types of methods.

2. Does the file, with the class Climber, have to be named Climber.java? If so, explain why?

3. What is the naming convention to name references to classes, methods, variables, and constants? Why are naming conventions important?

4. Given the following declarations, circle all the commands which are legal.

Robot karel = new Robot();

Athlete gary = new Athlete();

Climber lisa = new Climber(8);

Racer ralph = new Racer(3);

karel.move(); lisa.move(); gary.move();

karel.turnRight(); gary.turnRight(); gary.turnLeft();

gary.climbUpRight(); lisa.turnDownRight(); ralph.turnLeft();

mary.pickBeeper(); ralph.sprint(2); ralph.turnRight();

5. Given the following statements:

Climber Hillary = new HillClimber(12);

Hillary.climbUpRight();

What type of reference is Hillary? ______

What type of object does Hillary refer to? ______

6. What is Polymorphism? Give an example of when we used it?

7. When utilizing polymorphism, it is the ______that determines the behavior, while the ______determines the legality (allows you to compile).

8. Label the following statements as Valid or Invalid:

Robot karel = new Athlete(); ______

Athlete Pete = new Robot(); ______

Athlete speedy = new Racer(); ______

9. What does a constructor do? If there is more than 1 constructor for a class, how does the compiler determine which one to call?

Can you write a 3 parameter constructor for Athelete, specifying the location (x, y) and the number of beepers, with a fixed direction of WEST?

Write a statement which creates an Athlete using your 3 parameter constructor you wrote above.


10. Rewrite an equivalent section of code replacing the “for” loop with a “while” loop.

int sum = 0;

for (int k=0; k < data.length; k++)

sum = sum + data[k];

11. Write out a truth table to prove DeMorgan’s Laws:

12. Write a method to compute the sum of odd numbers from 1 to an input value of n.

13. What is an interface and why is it used?

14. Briefly explain how threads work.


15. Write methods for an Athlete class

a.  Pickup a pile of beepers and return the count

b.  Lay down a specified number of beepers

c.  Go until you reach a wall. Lay down a beeper if there is a gap (location without a beeper).

Methods from www.CodingBat.com

Program the following methods:

Warmup-1

monkeyTrouble

nearHundred

Logic-1

teenSum, answerCell, teaParty, twoAsOne,

inOrder, InOrderEqual, withoutDoubles, redTicket,

maxMod5, greenTicket, blueTicket, shareDigit,

sumLimit, caughtSpeeding, love6

Array-1

firstLast6, sameFirstLast, commonEnd, sum3,

rotateLeft3, maxEnd3, sum2


15. Vocabulary:

run-time

compiler

source code

JVM

java

byte-code

syntax

run-time

logical

threads

class

resource

application

concurrently

abstract

interface

main

1. The java file that you write is called ______.

2. Compiling code creates the ______.

3. Forgetting a semicolon would produce an ______error.

4. Trying to walk through a wall would produce an ______error.

5. When your program runs but still does not do what you expected, it has a ______error.

6. When you run an application, the ______method is called automatically.

7. When you save your java program, it should have a ______extension.

8. After compiling your code, the byte-code is saved with a ______extension.

9. When using ______, it appears to the user that several processes are executing at the same time. We can say the processes are running concurrently.

10. An ______is made of public and ______methods. The methods need to be implemented in the Classes which implements them.