Sunday, October 16, 2011

JAVA STATIC TUTORIAL









REVISED: Sunday, March 3, 2013




CONTENTS
I.   JAVA STATIC TUTORIAL INTRODUCTION
II.  JAVA STATIC METHOD
III. JAVA STATIC BINDING
IV. JAVA STATIC IMPORT
V.  JAVA STATIC TUTORIAL REFERENCES

YOU WILL LEARN:
1.  Static methods are methods that perform tasks without creating objects.
2.   Static methods are designed for frequently used simple tasks.
3.  How to create window dialog boxes.
4.  An easy to read way of calling Math class methods.

I.  JAVA STATIC TUTORIAL INTRODUCTION


Welcome to the “Java Static Tutorial.”
This tutorial has been prepared using Microsoft Windows, NetBeans IDE 7.0.1 and JDK 1.7.

If you find any errors or better ways of presenting the information please post them as tutorial comments.

II.  JAVA STATIC METHOD


A static method is a method that performs a simple common task without creating an object. Arguments in the static method call supply the static method with any data required to complete its task. The “this” keyword can not be used in a static method.

A. STATIC METHOD DECLARATION


Placing the keyword static before the return type in the method’s declaration declares the method static. For example:

public static void main( String[] args ){

}
//end main


An instance of a class (an object) is not created when the static main method is called.

B. STATIC METHOD SYNTAX


The syntax for calling a static method is its class name followed by a dot separator (.) and the method name; for example:

ClassName.methodName( arguments );


The syntax for the static main method is a special case. The Java Virtual Machine (JVM) begins execution of an application with the static main method.

C. CLASS MATH


All Math class methods are static and they are called using the class name followed by a dot separator (.) and the method name “static method syntax.” For example:

package MathPackage;

public class MathClass {

    public static void main( String[] args ) {
       
        int x = 9;
        int y = 3;
       
        System.out.println( Math.sqrt( x ) );
       
        System.out.println( Math.pow( x, y ) );
       
    }
//end main

}
//end MathClass


As shown in the above program, no Math objects were created before calling either method Math.sqrt or Math.pow.

Class Math Example Output:

3.0
729.0

D. JOPTIONPANE EXAMPLE


Static methods were designed for frequently used simple tasks; for example, coding dialog boxes. The following program is an example of using the static method JOptionPane to create simple window dialog boxes.

package JOptionPanePackage;

import javax.swing.JOptionPane;

/*
Use
JOptionPane.showXxxDialog
when you only need simple
window dialog.
*/

public class JOptionPaneClass {
   
    public static void main( String[] args ){
   
/*
JOptionPane.showInputDialog
uses a text field
to get a string from the user.
*/
        double numerator =
                Double.parseDouble(JOptionPane.showInputDialog
                        ( "This program computes a QUOTIENT. \n\n QUOTIENT =" +
                                " (NUMERATOR  /  DENOMINATOR) \n\n 1.  Type a  NUMERATOR," +
                                "  e.g., 999.999 \n 2.  then Click  OK  to continue; \n 3.  or, Click" +
                                "  CANCEL  to EXIT.\n\n" ));

        double denominator =
                Double.parseDouble(JOptionPane.showInputDialog
                        ( "1.  Type a  DENOMINATOR,  e.g., 3.3 \n 2.  then" +
                                " Click  OK  to continue; \n 3.  or, Click  CANCEL  to EXIT.\n " ));
       
        double quotient =
                (numerator / denominator);
       
/*
JOptionPane.showMessageDialog
displays a one-button dialog.
*/
        JOptionPane.showMessageDialog
        ( null,  "QUOTIENT equals:  \n " +quotient,
                "Click OK to Exit.",  JOptionPane.PLAIN_MESSAGE );
       
    }
//end main
   
}
//end class JOptionPaneClass

JOptionPaneClass Example Output:


The output assumes you type in 9 for the Numerator, and 3 for the Denominator, which gives you the 3.0 Quotient. 


Oops no JavaStaticEx2.gif!


Oops no JavaStaticEx3.gif!


Oops no JavaStaticEx4.gif!


III. STATIC BINDING


Static binding refers to all static method calls being resolved by the JVM at compile time.

IV. STATIC IMPORT


Static import improves program readability and reduces coding time.

A. Import One Static Member:


Use the following syntax to import one static member of a class.

import static java.packageName.ClassName.staticMemberName;

For example:

package MathPackage;

import static java.lang.Math.sqrt;

public class MathClass {

    public static void main( String[] args ) {
       
        int x = 9;
                 
        System.out.println( sqrt( x ) );
       
    }
//end main

}
//end MathClass

Import One Static Member Example Output:

3.0

B. Import All Static Members:


Use the following syntax to import all static members of a class.

import static java.packageName.ClassName.*;


Now you can call all Math class methods by name without writing Math in front of any Math method. For example:

package MathPackage;

import static java.lang.Math.*;

public class MathClass {

    public static void main( String[] args ) {
       
        int x = 2;
        int y = 3;
       
        System.out.println( pow( x, y) );  
       
    }
//end main

}
//end MathClass

Import All Static Members Example Output:

729.0

V.  JAVA STATIC TUTORIAL REFERENCES


Java How To Program Eighth Edition by Paul Deitel and Harvey Deitel (Upper Saddle River, N.J.: Pearson Education, Inc., 2010).


YOU HAVE LEARNED:
1.  Static methods are methods that perform tasks without creating objects.
2.   Static methods are designed for frequently used simple tasks.
3.  How to create window dialog boxes.
4.  An easy to read way of calling Math class methods.

Elcric Otto Circle









-->




-->




-->









How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




Friday, September 23, 2011

JAVA JDK ECLIPSE FOR WINDOWS









REVISED: Sunday, March 3, 2013



CONTENTS:
I.      JAVA JDK ECLIPSE FOR WINDOWS INTRODUCTION
II.   DOWNLOADING JAVA JDK
III.  INSTALLING JAVA JDK
IV.  DOWNLOADING ECLIPSE
V.    INSTALLING ECLIPSE
VI.  WRITING YOUR FIRST JAVA PROGRAM

YOU WILL LEARN HOW TO:
1. DOWNLOAD JAVA JDK
2. INSTALL JAVA JDK
3. DOWNLOAD ECLIPSE
4. INSTALL ECLIPSE
5. START WRITING JAVA PROGRAMS

I.  JAVA JDK ECLIPSE FOR WINDOWS INTRODUCTION


Welcome to the “JAVA JDK ECLIPSE TUTORIAL.”

II.  DOWNLOADING JAVA JDK


Start your browser then go to the following website:

http://www.oracle.com/technetwork/java/javase/downloads/index.html


Select the appropriate JAVA Standard Edition (SE) for your computer operating system.

I selected the Windows JDK7 +Java EE Bundle which includes the Java Platform, Enterprise Edition 6 Java Software Development Kit (SDK) Update 3 and the Java Development Kit (JDK) 7.

You need the Java Development Kit (JDK).  The JDK lets you write and compile JAVA programs.  You also need the Java Runtime Environment (JRE).  Depending on what you select, the JRE might be included with the JDK.  If the option you select is shown with two column headings, JDK and JRE, you should download both separately.

While you are downloading the Java JDK and JRE, which are appropriate for your computer, I recommend accepting all the defaults, to ensure you have the Java compiler properly downloaded.

III.  INSTALLING JAVA JDK


Perform the following steps:

A. From your Start menu click on "My Computer."

B. From "My Computer" click on C:\ your main hard drive.

C. From C:\ click on "Program Files."

D. From "Program Files" open the "Java folder."

E. From the "Java folder" open the folder with the name that includes jdk.

F. From the jdk folder open the bin folder.

G. From the bin folder right click on appletviewer.

H. From the appletviewer click on properties.

I. From properties copy the location path.

J Return to your Start menu and click on My Computer.

K. From My Computer right click on properties.

L. From properties click Advanced System Settings.

M. From Advanced System Settings click "Environment Variables."

N. From "Environment Variables" go to the top section named "New User Variables" and for "Variable name:" type "path"

O. From "Environment Variables" underneath "Variable name:" for "Variable value:" paste the location path you copied in Step 9.

P. From "Environment Variables" click OK and keep clicking OK on each window until you exit out and return to your desk top.

To test to see if everything works properly, from your desk top, click Start then click Run, type cmd, press Enter, and from the command line type javac then press Enter.

If everything works you will be in the java compiler and ready to code your first java program using Notepad or a similar text editor.

I do not recommend using a Notepad type text editor.

I recommend Eclipse.

IV.  DOWNLOADING ECLIPSE


Start your browser then go to the following website:

http://www.eclipse.org/downloads/


From the Eclipse website click on downloads.

Download the Eclipse that fits your needs, I downloaded Eclipse Classic.

I recommend accepting all the defaults and you will have the Java Eclipse IDE downloaded.

V.  INSTALLING ECLIPSE


The Eclipse download will be a zip file.

Use WinZip or a similar package to unzip and extract the download.

I recommend accepting all the extraction defaults.

A. From your Start menu click on "My Computer."

B. From My Computer click on C:\ your main hard drive.

C. From C:\ click on "Program Files."

D. From "Program Files" open the Eclipse folder.

E. Right click on the purple round Eclipse circle icon, the one with the three white horizontal lines and select "Create Shortcut."

F. Click and drag the shortcut to your desktop.

VI.  WRITING YOUR FIRST JAVA PROGRAM


Click the Eclipse shortcut on your desktop. When Eclipse opens follow these steps:

A. Click File, then click New, then click "Java Project."

B. From the Project Name window, type is whatever name you prefer, and then press Finish.

C. You will be returned to the first Eclipse window.

D. On the left side of the window you will see the Project Name you entered. Click the icon to the left to the Project Name and the project will be expanded.

E. Click source the top option src, then click New, then click Class.

F. A new window will open requesting a class name. Type in whatever name you prefer then press Finish.

G. The next window will show the start of the class code. Eclipse will start the code for you. It will say public class {…}.

H. Copy and then paste the following code between the two {…}.

public static void main(String args[]){
    System.out.println("Hello World!");
}


Look at the toolbar at the top of the window.  Under Refactor you will see an arrow icon pointing to the right.  When you move your cursor over the icon it will say Run and your class name.  Click the run icon and your first Java program will run.  If everything is working properly, in the bottom pane, it will print “Hello World!”

Congratulations!  You will soon see Java is easy to learn and fun to use.  Have fun! 


YOU HAVE LEARNED HOW TO:
1. DOWNLOAD JAVA JDK
2. INSTALL JAVA JDK
3. DOWNLOAD ECLIPSE
4. INSTALL ECLIPSE
5. START WRITING JAVA PROGRAMS

Elcric Otto Circle





-->




-->




-->










How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




Tuesday, September 20, 2011

JAVA CLASS DESIGN “E = MC^2” TUTORIAL









REVISED: Sunday, March 3, 2013




CONTENTS:
I. INTRODUCTION
II. E=MC2
III. CLASS
IV. INSTANCE VARIABLES
V. CONSTRUCTORS
VI. INSTANTIATING AN OBJECT
VII. CONSTANTS
VIII. MAIN METHOD
IX. METHODS
X. EXAMPLE PROGRAM
XI. REFERENCES

YOU WILL LEARN:
1.  Instance variables.
2.  Access modifiers.
3.  Constructors.
4.  Instantiating an object.
5.  Constants.
6.  How to use the main() method.
7.  Methods.

I. INTRODUCTION

Welcome to Java Class Design E=MC2.
Atomic Bomb Explosion

This tutorial was prepared using Microsoft Windows, NetBeans IDE 7.0.1 and JDK 1.7.

If you find any errors or better ways of presenting the information please post them as tutorial comments.

II. E=MC2

The “Java ‘Energy Equals Mass Times the Speed of Light Squared’ Tutorial” title was selected to introduce the reader to the Java methods used to demonstrate key points discussed in the tutorial.

In order to create tutorial discussion examples we will write a Java program to compute, “Energy equals mass times the speed of light squared.” Our discussion examples will include a Java energy class and an object of that class, and of course instance variables and methods for computations and printouts.

III. CLASS

Our Java source code begins in the following order: first, a package declaration; second, an import declaration; and third, a class declaration.

The “EEqualsMCSquaredPackage” will be used to contain our class “EEqualsMCSquaredClass.” Java uses packages to group classes in order to make libraries.

We start with the package declaration as shown below:

/*
Classes are organized into packages; therefore, if you want to reuse an existing class, instead of copying the class into your program you import the package containing the class.
 */
package EEqualsMCSquaredPackage;

We will need to square the speed of light; therefore, we import “java.lang.Math.*” in order to make the tutorial coding easier to read.

/*
Static import of math class methods enable calling each Math class method by name without writing Math in front of the Math method.
 */
import static java.lang.Math.*;

Our class declaration starts with the “public” access modifier keyword; therefore, it can be accessed from anywhere.

Next the class declaration has the keyword “class” followed by the class’s name “EEqualsMCSquaredClass.”

Immediately following the class name is a set of open and closed braces “{ }” which will enclose the body of the class.

/*
Class declaration.
 */
public class EEqualsMCSquaredClass {
     
}
/*
End class EEqualsMCSquaredClass.
*/

IV. INSTANCE VARIABLES

Local variables are declared and used within a method and when the method terminates the local variables are lost.

An object has attributes (instance variables also called data fields or class declaration variables) that are declared when their class is declared and are used within its class. Each object has its own copy of the instance variables. When an object is created Java automatically calls a constructor which initializes the objects instance variables. The life of the object’s copy of its instance variables is the life of the object.

The instance variables for the example program are as follows:

/*
Class declaration.
 */
public class EEqualsMCSquaredClass {

    private double M;
/*
Mass of atoms.
*/

    private double E;
/*
Energy released.
*/

    private double SD;
/*
Sticks of dynamite equivalent to E.
*/

The access modifiers: “public,” “private, “protected” and the default modifier (no modifier) control access to a class’s instance variables. The “private” instance variables can only be accessed by a “public” method from inside their class. The “public” instance variables can be accessed from anywhere in the application. The access to “protected” instance variables is between the access of “public” and “private.” You have to be in the same package to access “protected” instance variables from inside their class.

V. CONSTRUCTORS

As previously mentioned above, each object has its own copy of the instance variables. When an object is created Java automatically calls a constructor which initializes the objects instance variables. The life of the object’s copy of its instance variables is the life of the object.

The instance variable constructors for the example program are as follows:

/*
Object created no arguments passed in default constructor executed. 
*/
    public EEqualsMCSquaredClass( ){
        super();
         
        System.out.println( "\n     ****************************************************  \n" );

        System.out.println( "     OBJECT CREATED\n" );

        System.out.println( "     NO ARGUMENTS PASSED IN\n" );
        System.out.println( "     DEFAULT CONSTRUCTOR EXECUTED!\n" );

        System.out.println( "     ****************************************************  \n" );
         
    }
     
/*
Object created three arguments passed in and they match  constructor parameters by type and number.
*/
    public EEqualsMCSquaredClass( double m, double e, double sd ){
         
        M = m;

        E = e;

        SD = sd;
         
        System.out.println( "\n     ****************************************************  \n" );

        System.out.println( "     OBJECT CREATED\n" );

        System.out.println( "     THREE ARGUMENTS PASSED IN\n" );

        System.out.println( "     AND THEY MATCH CONSTRUCTOR PARAMETERS BY TYPE AND NUMBER\n" );

        System.out.println( "     CONSTRUCTOR EXECUTED!\n" );

        System.out.println( "     M   = " + M + "\n" );

        System.out.println( "     E   = " + E + "\n" );

        System.out.println( "     SD  = " + SD + "\n" );

        System.out.println( "     ****************************************************  \n" );
     
    }
  
The constructor declaration is the control in the sense that the constructor’s parameters in the constructor declaration have to match the arguments passed in to the constructor by number and type to execute the constructor.

All constructors are located within the class and outside of the class methods.

Every class has at least one constructor. If you declare a default constructor, Java will not create a default constructor for you. The first line inside a default constructor must be a call to the super class constructor “super();” or “this” but not both.

A constructor method:

A. Can be used to assign initial values to an object’s instance variables.

B. Does not have any return type.

C. Has the same name as the class it is in.

D. Has the same access modifier as the class it is in.

E. Can be overloaded.

F. The “this” keyword can be used to ensure an object accesses its own attributes (instance variables also called data fields or class declaration variables).

VI. INSTANTIATING AN OBJECT

(So far we have presented the tutorial in the same order as the example program’s code. However, “constructors” and “instantiating an object” go hand in hand; therefore, to make it easier to explain things we will jump ahead. However, the “instantiating an object” code is located where it is in the example program because the M, E, SD local variable arguments we need to pass to the constructor have not been coded until then.)

When a new object of a class is created a constructor for that class is called automatically to initialize the attributes (instance variables also called data fields or class declaration variables) of the new object.

We start our object declaration with “EEqualsMCSquaredClass” the class name. Next we declare the name of our object, which in the example program is “E1.” Then we type the assignment symbol “=” followed by the keyword “new.” We end the object declaration with the class name “EEqualsMCSquaredClass” followed by an open and closed parenthesis “( M, E, SD )” containing the “arguments” we are passing to the constructor and a statement ending semicolon “;.”

For example:

/*
Creates a new  EEqualsMCSquaredClass class object named E1 passes three arguments to the constructor.
*/
EEqualsMCSquaredClass E1 = new EEqualsMCSquaredClass( M, E, SD );

The arguments passed from the instantiating an object code must match the constructor’s parameters by number and type; however, they do not have to have the same name.

VII. CONSTANTS

Within the class body, after the constructors, we declare two constants: “C” the speed of light in meters per second, and “D” the Joules of energy in one stick of dynamite. For example:

/*
C = speed of light, measured in meters per second (mps).
*/

public static final double C = 299792458;
     
/*
D = Joules of energy in one stick of dynamite.
*/

public static final double D = 2100000;

The declaration of “C” starts with the “public” access modifier keyword. Placing the keyword “static” before the return type in the declaration declares the variable static which means “C” is a class variable common to all objects of the class. The keyword “final” means the class variable “C” is a constant. Also, “final” is used to ensure “C,” the speed of light, is not modifiable by assignment.

We follow the same steps to declare “D.”

VIII. MAIN METHOD

The method main begins the execution of the application and is shown as follows:

/*
main() method begins execution of Java application.
*/

     public static void main( String[] args ){
     }
/*
End main.
*/

The main method declares the local variables and makes the method calls.

A. LOCAL VARIABLES

The following local variables are declared and used within the main method; and, when the main method terminates the local variables are lost.

The type of the function call must match the return type of the method being called.

Each function’s arguments passed to a method must match the number and type of the called method’s parameters.

/*
M = the total mass of hydrogen atoms, measured in kilograms (kg), in one kg of pure water.
*/
double M = .111;

/*
Computes j of energy released equals kg of atom mass times the mps of light squared.
 */
double E = setEnergyReleased( M, C );

/*
Computes equivalent sticks of dynamite.
*/
double SD = setSticksOfDynamite( E, D );

B. METHOD CALLS

The arguments passed to the methods must match the called method’s parameters by number and type.

Notice in the examples below we are using the new object we created, named E1, to call methods. We are doing this to pass the appropriate attributes of E1 to the method as arguments. If we created multiple objects, each object we created would have its own unique attributes.

/*
Calls method using new object and  prints kg of atom mass.
*/
E1.one( M );

/*
Calls method using new object and prints mps of light.
*/
E1.two( C );

/*
Calls method using new object and prints j of energy released and prints equivalent sticks of dynamite.
*/
E1.three( E, SD );

IX. METHODS

As shown below, the method’s parameters control the number and type of arguments passed to the method from the calling function.

Each method’s type must be the type returned by the method. The function calling the method must have the same type as the type returned by the method.
    
/*
Computes j of energy released equals kg of atom mass times the mps of light squared.
*/
    public static double setEnergyReleased( double M, double C ) {
         
        return ( M * pow( C, 2 ) );
         
    }
/*
End getEnergyReleased method.
*/
     
/*
Computes equivalent sticks of dynamite.
*/
    public static double setSticksOfDynamite( double E, double D ) {
                 
        return ( E / D );
         
    }
/*
End getSticksOfDynamite  method.
*/
     
/*
Prints kg of atom mass.
*/
    public void one( double M ) {
         
        System.out.println( "Given that:\n" );

        System.out.println( "1.  One kilogram (kg) of pure water contains a mass of " );

        System.out.println("    M = " + M + " kg of hydrogen atoms.\n" );
         
    }
/*
End method one.
*/
     
/*
Prints mps of light.
*/
    public void two( double C ) {
         
        System.out.println( "2.  And, C = the speed of light which is approximately" );

        System.out.println( "    " + C + " meters per second (mps).\n");
         
    }
/*
End method two.
*/
     
/*
Prints j of energy released prints equivalent sticks of dynamite.
*/
    public void three( double E, double SD ) {
         
        System.out.println( "3.  Then, using the equation E = M ( C * C )" );

        System.out.println( "    the energy which could be released from one kilogram of pure water," );

        System.out.println( "    excluding the energy released by the oxygen atoms therein, is approximately" );

        System.out.println( "    " + E + " Joules (j).\n" );

        System.out.println( "    A stick of dynamite contains roughly 2.1E6 Joules of energy.\n" );

        System.out.println( "    Therefore, the energy released equals approximately " + SD + " sticks of dynamite!\n" );

        System.out.println( "     ****************************************************  \n\n" );
         
    }
/*
End method three.
*/

X. EXAMPLE PROGRAM SOURCE CODE

The example program is as follows:

/*
Classes are organized into packages; therefore, if you want to reuse an existing class, instead of copying the class into your program you import the package containing the class.
*/
package EEqualsMCSquaredPackage;

/*
Static import of math class methods enable calling each Math class method by name without writing Math in front of the Math method.
*/
import static java.lang.Math.*;

/*
Class declaration.
 */
public class EEqualsMCSquaredClass {
     
    private double M;
/*
Mass of atoms.
*/

    private double E;
/*
Energy released.
*/

    private double SD;
/*
Sticks of dynamite equivalent to E.
*/
     
/*
Object created no arguments passed in default constructor executed. 
*/
    public EEqualsMCSquaredClass( ){
        super();
         
        System.out.println( "\n     ****************************************************  \n" );

        System.out.println( "     OBJECT CREATED\n" );

        System.out.println( "     NO ARGUMENTS PASSED IN\n" );
        System.out.println( "     DEFAULT CONSTRUCTOR EXECUTED!\n" );

        System.out.println( "     ****************************************************  \n" );
         
    }
     
/*
Object created three arguments passed in and they match  constructor parameters by type and number.
*/
    public EEqualsMCSquaredClass( double m, double e, double sd ){
         
        M = m;

        E = e;

        SD = sd;
         
        System.out.println( "\n     ****************************************************  \n" );

        System.out.println( "     OBJECT CREATED\n" );

        System.out.println( "     THREE ARGUMENTS PASSED IN\n" );

        System.out.println( "     AND THEY MATCH CONSTRUCTOR PARAMETERS BY TYPE AND NUMBER\n" );

        System.out.println( "     CONSTRUCTOR EXECUTED!\n" );

        System.out.println( "     M   = " + M + "\n" );

        System.out.println( "     E   = " + E + "\n" );

        System.out.println( "     SD  = " + SD + "\n" );

        System.out.println( "     ****************************************************  \n" );
     
    }
     
/*
C = speed of light, measured in meters per second (mps).
*/
    public static final double C = 299792458;
     
/*
D = Joules of energy in one stick of dynamite.
*/
    public static final double D = 2100000;
         
/*
Main method begins execution of Java application.
*/
    public static void main(String[] args) {
             
/*
M = the total mass of hydrogen atoms, measured in kilograms (kg), in one kg of pure water.   */
        double M = .111;
         
/*
Computes j of energy released      equals kg of atom mass times the mps of light squared.
*/
        double E = setEnergyReleased( M, C );
         
/*
Computes equivalent sticks of dynamite.
*/
        double SD = setSticksOfDynamite( E, D );
         
/*
Creates a new EEqualsMCSquaredClass class object named E1 passes three arguments to the constructor.
*/
        EEqualsMCSquaredClass E1 = new EEqualsMCSquaredClass( M, E, SD );
         
/*
Calls method using new object      and  prints kg of atom mass.
*/
        E1.one( M );
         
/*
Calls method using new object      and prints mps of light.
*/
        E1.two( C );
         
/*
Calls method using new object      and prints j of energy released         and prints equivalent sticks of dynamite.
*/
        E1.three( E, SD );
                     
    }
/*
End main.
*/
     
/*
Computes j of energy released    equals kg of atom mass times the mps of light squared.
*/
    public static double setEnergyReleased( double M, double C ) {
         
        return ( M * pow( C, 2 ) );
         
    }
/*
End getEnergyReleased method.
*/

/*
Computes equivalent sticks of dynamite.
*/
    public static double setSticksOfDynamite( double E, double D ) {
                 
        return ( E / D );
         
    }
/*
End getSticksOfDynamite method.
*/
     
/*
Prints kg of atom mass.
*/
    public void one( double M ) {
         
        System.out.println( "Given that:\n" );

        System.out.println( "1.  One kilogram (kg) of pure water contains a mass of " );

        System.out.println("    M = " + M + " kg of hydrogen atoms.\n" );
         
    }
/*
End method one.
*/
     
/*
Prints mps of light.
*/
    public void two( double C ) {
         
        System.out.println( "2.  And, C = the speed of light which is approximately" );

        System.out.println( "    " + C + " meters per second (mps).\n");
         
    }
/*
End method two.
*/
     
/*
Prints j of energy released  prints equivalent sticks of dynamite.
*/
    public void three( double E, double SD ) {
         
        System.out.println( "3.  Then, using the equation E = M ( C * C )" );

        System.out.println( "    the energy which could be released from one kilogram of pure water," );

        System.out.println( "    excluding the energy released by the oxygen atoms therein, is approximately" );

        System.out.println( "    " + E + " Joules (j).\n" );

        System.out.println( "    A stick of dynamite contains roughly 2.1E6 Joules of energy.\n" );

        System.out.println( "    Therefore, the energy released equals approximately " + SD + " sticks of dynamite!\n" );

        System.out.println( "     ****************************************************  \n\n" );
         
    }
/*
End method three.
*/
         
}
/*
End class EEqualsMCSquaredClass.
*/

Example Program Output:

     ************************************  

     OBJECT CREATED

     THREE ARGUMENTS PASSED IN

     AND THEY MATCH CONSTRUCTOR PARAMETERS BY TYPE AND NUMBER

     CONSTRUCTOR EXECUTED!

     M   = 0.111

     E   = 9.976182483978676E15

     SD  = 4.750563087608893E9


     *************************

Given that:

1.  One kilogram (kg) of pure water contains a mass of
    M = 0.111 kg of hydrogen atoms.

2.  And, C = the speed of light which is approximately
    2.99792458E8 meters per second (mps).

3.  Then, using the equation E = MC2
    the energy which could be released from one kilogram of pure water,
    excluding the energy released by the oxygen atoms therein, is approximately
    9.976182483978676E15 Joules (j).

    A stick of dynamite contains roughly 2.1E6 Joules of energy.

    Therefore, the energy released equals approximately

    4.750563087608893E9 sticks of dynamite!
     ************************************ 

XI. REFERENCES

CS106A Computer Science I: Programming Methodology Lectures by Mehran Sahami, Associate Professor, Computer Science Department (450 Serra Mall, Stanford, CA: Stanford University, 2007).

Java How To Program Eighth Edition by Paul Deitel and Harvey Deitel (Upper Saddle River, N.J.: Pearson Education, Inc., 2010).

YOU HAVE LEARNED:
1.  Instance variables.
2.  Access modifiers.
3.  Constructors.
4.  Instantiating an object.
5.  Constants.
6.  How to use the main() method.
7.  Methods.

Elcric Otto Circle




-->

-->

-->





How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"