|
Style 1
// simplest one to start with
package untitled1;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
public static void main(String args[])
{
DECLARE ALL VARIABLES
WRITE ALL JAVA COMMANDS
System.exit(0);
}
}
Style 2
// introduction to using functions also
// includes try - catch blocks to give you an
// idea of the logic flow for your first program
// Pay attention to the brackets and the order
// I used two arrays as an example but you will
// have more
package untitled1;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
public static void main(String args[])
{
int scores[][] = new
int[10][5];
float avg[] = new
float[10];
DECLARE VARIABLES or
arrays only known in MAIN
MUST be passed to
functions if the functions
are to access them
try
{
// open files
do
{
// read record
// break it into logical pieces
// store it in arrays
} while ( etc )
call function1 ( scores, avg );
// sort all data based on avg arfray
call function2 ( etc ) // printing
}
catch
{
// output
error condition
}
System.exit(0);
} // end main method
function1 ( int scores[][], float avg[]
)
{
code to comput averages etc
}
function2 // all arrays must be passed
{
code to do output
}
} // end class
Style 3
// creating an oblect of a class and
// placing all code in the constructor
package untitled1;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
public Application1() // construstor method
for class
{
DECLARE ALL
VARIABLES
WRITE SOURCE CODE
}
public static void main(String args[])
{
Application1 app = new Application1(); // create object
System.exit(0);
}
}
Style 4
// best style for OOP using functions (methods
)
// advanced 314 students
package untitled1;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Application1
{
DECLARE GLOBAL VARIABLES calles INSTANCE VARIABLES
public Application1() // construstor method
for class
{
Declare all arrays
etc
start the logic of
your program
and call the
methods (functions) below when needed
}
public method1
{
code
}
public method2
{
code
}
public method3
{
code
}
ETC
public static void main(String args[])
{
Application1 app = new Application1(); // create object
System.exit(0);
}
}
|