EXAM 1
CS 46A Fall 2013
Exam Rules
- The exam is over at 1:10
- Spend the last 5 minutes uploading your code.
- Develop your solutions in Bluej. When they compile,submit in Codecheck. Download the .signed.zip file and upload to Canvas
- Turn off the WiFi on your phone. Only connect to the internet with one device.
- You may use any books, notes, files on your computer.
- You may NOT use any software that allows communication with someone else.
- You may NOT communicate with anyone during the exam.
- You may NOT use the work of anyone else without attribution.
- You may NOT open any programs or web sites that allow communication with someone else. No messenger, chat, email, discussion forum, Facebook, Twitter, etc.
- The proctor will randomly inspect laptops. If your laptop is inspected, you need take the hands off the keyboard immediately.
- Submit all the to the .signed.zip files in Canvas Assignment area. Upload all at the same time
1. (10 points) Complete the methods in the StringUtility class.
- public String getFirst(String s) - returns the first letter in the string
- public String getLast(String s) - returns the last letter in the string
- public int getNumberOfCharacters(String s) - returns the number of charactrs in this string
Codecheck URL : http://go.code-check.org/codecheck/files/13091923354350886398188892317
2. (10 points) Complete the method leetSpeak method in the Leet class. Do not change the original word in any way.
- public String leetSpeak() - returns a string in which these substutions have been made: replace a with 4, r with 12, and b with 8
- public String getWord() - returns the original word
Example: break -> 812e4k
Codechek URL: http://go.code-check.org/codecheck/files/13091922564938792600020041313
3. (10 points)The planet Java has some very strangly shaped buildings - one is shown below along with its dimensions. You are to complete the Building classby implementing the volume method.
The planet does not have breathable air and so the buildings need to be filled with air earth normal pressure. One of the methods of the Building class calulates the volume of the Building bases on the height, x, so the engineers can figure out how much air will be needed.
The volume of the building is the volume of the rectangle + the volume of the cube.
(3x)(2x)(x) + 2x(x2)π = 6x3 + 2x3π
(Don't spend time trying to figure this out. Just use the formula)
Use Math.PI

Codecheck URL: http://go.code-check.org/codecheck/files/13091922292178357749823441713
4. (10 points) Complete the class called SelectionDemo. Its main method will do the following.
- Create a scanner.
- Prompt the user System.out.print("Enter a number: ") Use this exact prompt - copy and paste it.
- Get the user response.
- If the user answered:
- a number greater than 1,000,000, print exactly this: "Greater"
- a number less than 1,000,000, print "Less"
- a number equal to 1,000,000, print "Equal"
- Use the correct statement structure.(if / else if / else)
Codecheck URL: http://go.code-check.org/codecheck/files/13100601023twfsu5ceaz5y3112n3kmwwl0
5. (10 points)You are given a Sphere class. Your job is to complete the SphereDemo's main method to do these things.
- Create a Sphere. Use the variable diameter to specify the diameter. (Do not use the literal 10 in the code you add. Do not change the variable definition).
- Calculate and print the volume of the sphere. Use the statement below to print
- Grow the Sphere by the given delta. (Do not use the literal 5 in the code you write. Use delta as the parameter)
- Calculate and print the new volume of the sphere.
- Now create a new sphere whose diameter is twice the diameter of the first sphere (use diameter * 2).
- Calculate and print the volume.
Use this statement to print the volume:
System.out.printf("Volume:%8.2f\n", volume);
Codecheck URL: http://go.code-check.org/codecheck/files/13091718517334995187890390625
6. (10 points) Complete the class DrawingPractice. Using the graphics package from the Udacity videos (also included in the zip of the exam) draw a rectangele at at coordinates (30, 20) with a width of 50 and a height of 40. Create the Ellipse that fits is surrounded by tis rectangle. Fill it with the color red defined in tthe Color class. Lastly, draw a line from the upper left-hand corner of the rectangle to the lower right-hand corner.
The image should look like this.

Codecheck URL: http://go.code-check.org/codecheck/files/13091722431343873532525452140