Midterm Exam #1 | CPTR 105 | March 16th, ’09

Name:


Directions: The midterm consists of two programs that you need to code. You can do this in either Netbeans or just Notepad. The programs will test your Java and general programming skills. Some point to remember:


Program 1

Write a program in which you do all of the following:

  1. declare 8 variables belonging to the 8 primitive types (int, short, float, ...) and assign some values in each one. Then print these variables’ values using System.out.println().
  2. declare a String variable—call it myString—and store a 15-character string in it (for e.g.,
    "The Golden Rule"). Then print out:
  3. Ask the user to input a string. If the length of this string is even, concatenate it to myString in any order, and display the new string; otherwise display a lowercase version of the new string.

Program 2

Write a program that asks the user for the radius of a circle. Store this as a double value in a double variable. Then calculate and print out the area and circumference of the circle. Make sure your output looks like this:

For a circle with radius 12.52, the area is 492.196, and circumference is 78.6256

Note: Area of a circle is π*r*r; circumference is 2*π*r.