CCHS Math Unit 1 Test - In Class Name: AP CS

advertisement

CCHS Math

AP CS-A

Unit 1 Test - In Class

(120 Points)

Name: _____________________

9/13/13

1.

In 1991, James _________ and Patrick Naughton from Sun Micro Systems developed JAVA.

Originally, JAVA was designed for use in: ________________.

2.

Describe the purpose of the JAVA VIRTUAL MACHINE (JVM).

Include a simple sketch to amplify your explanation which should include examples of source files, the compiler, Class and library files, the JVM, and the final program running on a generic machine.

3.

Precisely write the code for the method that must be included in ANY java application.

Statements within this method are executed whenever the java program runs. Inside this method, write correct code to: a.

invoke a method getName having a string as a return value and b.

Invoke a method calculateAge returning nothing

4.

Problem: a.

Explain compile time and run time errors. Includes examples of each type of error. b.

What is an exception? Provide an example.

Unit 1 (In Class).docx Page 1 of 6

CCHS Math

AP CS-A

Unit 1 Test - In Class

(120 Points)

Name: _____________________

9/13/13

5.

Identify and explain the three essential characteristics of a computer system algorithm: a.

________________________ b.

________________________ c.

________________________

6.

Write Pseudocode:

Problem Description: The Canon City water department charges all customers a fixed fee

(meter charge) of $22.35 on each monthly bill. For each 1,000 gallons up to 12,000 gallons the water charge is $3.50 per 1,000 gallons. For usage volumes between 12,000 and 20,000 gallons, the cost per 1,000 gallons is $4.50. For volumes above 20,000 gallons, the cost is $6.00 per 1,000 gallons. Assume all water usage is billed to the nearest 1,000 gallons a.

Write the pseudocode for a computer algorithm which will compute a customer’s bill. b.

Test your pseudocode by calculating the bill of a customer using 21,200 gallons in one month.

Pseudo Code: Test Code:

Unit 1 (In Class).docx Page 2 of 6

CCHS Math

AP CS-A

Unit 1 Test - In Class

(120 Points)

Name: _____________________

9/13/13

7.

Writing Algorithms/Code:

The infinite series for the trig function sine (with x in radians) is given by: a.

In a single method (main method(?)), write the logic algorithm and basic code to compute the value of sine for a specific angle x to an accuracy of 3 decimal places. b.

Test your algorithm by manually computing sin(pi/3) = 0.866

Pseudo Code: Test Code:

Unit 1 (In Class).docx Page 3 of 6

CCHS Math

AP CS-A

Unit 1 Test - In Class

(120 Points)

Name: _____________________

9/13/13

8.

For class CrabWorld, write the code for a method populateWorms() that will populate the world with 10 randomly placed (in both x and y directions) worms. Use the “if / else if / else” statement as the mechanism to implement this code (or some other clever method). The brute force method shown to the right and used by the author is not acceptable.

If you have studied and know the “for” statement, you may use that statement to implement the code. addObject(new Worm(), 20, 500); addObject(new Worm(), 30, 200); addObject(new Worm(), 60, 90); addObject(new Worm(), 80, 310); addObject(new Worm(), 150, 50); etc.

Unit 1 (In Class).docx Page 4 of 6

CCHS Math

AP CS-A

Unit 1 Test - In Class

(120 Points)

Name: _____________________

9/13/13

9.

Assume you create 3 crabs in the world that eat worms. Write the code to count the number of worms eaten by each crab and stop the game when the TOTAL numbers of worms eaten by the

3 crabs == 20.

Assume 25 worms initially populate the world.

Unit 1 (In Class).docx Page 5 of 6

CCHS Math

AP CS-A

Unit 1 Test - In Class

(120 Points)

Name: _____________________

9/13/13

10.

Write the code for worms to instantiate (“reappear”) after being eaten. The code should induce randomness in not only the LOCATION and TIME after being eaten, but also WHETHER a worm will be instantiated at all. Make the randomness reasonable and comment in your code any randomness parameters.

Unit 1 (In Class).docx Page 6 of 6

Download