| Lab Objectives
 | 
Getting a Printout of Your Program Activate your terminal window then type in the following command (the first character is the letter l, not the number 1):
lpoptions -d CSLabDon't be alarmed - a lot of messages will be printed! Just ignore them. This should set the lab printer as your default printer. You shouldn't need to do this command again - the default should stay set even after you log out.
***Be sure you are in your lab3 directory, then type the following command in the xterm window:
    enscript -2rG StringManip.java
Your printout should appear on the printer.
       double price = 34.56;
The program should produce output as follows:
       Variable Type:       double
       Variable Name:       price
       Initial Value:       34.56
The program will use methods from the String class to determine the
parts of the string.  Clearly the type, variable name, and the
initial value of the variable are all substrings of the original
statement so the substring method will be very important.  However,
the substring method needs to have some information about where (the
indices) to break the string up.  In particular, the substring
method requires you to specify the starting index of the substring
you want to extract and the index of the character that marks the
end of the substring (the index of the character that is one character
beyond the last character in the substring). 
For example in the declaration above we would need the indices
of the positions indicated in the following diagrams 
to extract the variable type, the variable
name, and the initial value from the declaration/initialization 
statement: 
                    double price = 34.56;
                    ^     ^
                    ^     ^
		    |     |     
Variable type:    starts  goes up to
                  here    (but does not 
                           include) here
                   double price = 34.56;
                          ^    ^
                          ^    ^
		          |    |     
Variable name:         starts  goes up to
                       here    (but does not 
                               include) here
                    double price = 34.56;
                                   ^    ^
                                   ^    ^
		                   |    |     
Initial value:                  starts  goes up to
                                here    (but does not 
                                         include) here
Of course for this particular example we could count to find the
indices.  However we want a more general approach that would
work for every declaration/initialization statement that is
in the correct form.
For that, the indexOf  method is 
very useful.  The following is the signature for the method.
        
       int  indexOf(String str)
 
       Returns the index within this string of the first occurrence of the 
       specified substring (str).
For example, suppose we have the following:
       String title = "Java Software Solutions";
Then, title.indexOf("Soft") would be 5, the index of the beginning
of the string "Soft" in the title.  Similarly, title.indexOf("v") would
be 2, the index of the first occurrence of the letter v.
We can use the indexOf method to find the locations of the characters that separate the parts of the declaration/initialization. Notice in the example above, the first blank space marks the end of the type (the word "double" in this case). So, if we know the index of the first blank space we can extract the substring for the type (that would tell us the index of the blank space that marks the end of the type and we know the index of the beginning of the type, right?).
Similarly knowing the index of the first blank space also lets us know the index of the first character in the variable name (we assume there is only one blank space) - what is the relationship between the index of the first blank character and the index of the first character in the variable name?
Download the file DeclarationParse.java, open it in Emacs, and complete the program using the comments as a guide. Be sure to test the program on several different declaration/initializations. The program should work correctly for declaration/initialization statements that have correct syntax including the semi-colon at the end.
***Print your program to hand in (use the enscript command from before - use the up arrow key to retrieve it then replace the file name with DeclarationParse.java).
           range = sin(2*angle) * velocity2 / g
where g is the gravitational constant (which is about 32.174 feet/sec/sec
in English units) and the angle is measured in radians. The range will
be given in feet.
You need to:
To be fair, she wants the "WRKE Super Prize Birthday" to be selected at random. Write a complete Java program that will randomly generate a month (1-12) and day (1-31) for her to announce on the air. Your program should print out a message that includes some text (e.g. "The WRKE Super Prize Birthday is: ") as well as the numeric representation of the date (e.g. "2/28"). Your program must include comments to explain why you will occasionally produce an invalid date.
Print the completed program.
//*****************************************************************************
// FILE: SimpleShape.java
//
// AUTHOR: *** Your name here!!! ***
//
// Draws simple shapes on the screen in random positions.
//*****************************************************************************
import javax.swing.JFrame;
import java.awt.*;
public class SimpleShape extends JFrame
{
    //-----------------------------------------
    // Create and display application frame
    //-----------------------------------------
    public static void main(String[] args)
    {
	SimpleShape frame = new SimpleShape();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setSize(600, 400);
	frame.setVisible(true);
    }
    //--------------------------------------------------------------
    // Assign random position and size then draw each of 3 shapes
    // on the Graphics object named page.
    //--------------------------------------------------------------
    public void paint(Graphics page) 
    {
	final int PAGE_WIDTH = getWidth(); // width of drawing area in pixels
	final int PAGE_HEIGHT = getHeight(); // height of drawing area in pixels
	// Draw a rectangle in the background color to cover the whole window
	page.setColor(Color.white);
	page.fillRect(0, 0, PAGE_WIDTH, PAGE_HEIGHT);
	// Declare variables
	int x, y; // x and y coordinates of upper left-corner of the shape
	int width, height; // width and height of the shape
	// Set the color for the next shape to be drawn
	page.setColor(Color.blue);
	// Assign the corner point and width and height
	x = 200;
	y = 125;
	width = 200;
	height = 150;
	// Draw the oval
	page.fillOval(x, y, width, height);
    }
   
}
Study the code noting the following:
Save the file SimpleShape.java to your lab3 directory. Now do the following:
Run the program to test the changes.
HAND IN:
tar czf yourNamelab3.tgz .Where yourName is your name (first name is fine).
~ingram/CPSC120/yourname(replace yourname with one of the following: john, jon, brandon, heather, emerson, trent, isabella, tamara, kiel, chris, kelsey, roxe, jaymes)