



|
|
Byron's CSC212 Web Site
|
Class Notes
Monday October 16 , 2000
|
|
|
Objective Application Architecture
Class Notes --
Monday October 16 , 2000
CSC212 - October 16, 2000
==========================
Lecture Topic: Objective Application Architecture
DEF: The OBJECTIVE APPLICATION ARCHITECTURE is the
application architecture in which:
1) The "Perfect" object for solving the program at hand
is created from a specially tailored class.
The "Objective" approach:
Ex: The "objective" solution to the line of squares
problem.
class ----------
{
static public void main (-----)
{
LineOfSquares los = new lineOfSquares();
double p = los.perimeter();
IO.println("The Perimeter is " + p);
}
// or IO.print("The Perimeter is ");
// IO.print(los.perimeter());
// IO.printnl();
class LineOfSquares
{
// Instance Variables
private int nrSquares;
private double edgeLength;
}
// Constructor
public LineOfSquares()
{
// Prompt
IO.print("How Many Squares? ");
nrSqyares = IO.read_int();
IO.print("Area of Figure? "):
double areaOfFigure = IO.read_double();
double areaOfSquare = areaOfFigure/nrSquares:
edgeLength = Math.sqrt(areaOfSquare);
}
// Reference other "class"
public double perimeter()
{
// Computational Method
return edgeLength * eeCount();
}
private int eeCount()
{
return (nrSquares * 2) + 2;
}
}
// LineOfSquares
NOTE: Look on CS1 for "Examples of Application
Architecture Programs".
Use for help on programming assignment.
DEF: IMPERATIVE PROGRAMMING is a style of programming
which reatures "commands".
Remark: Characteristics of the Imperative Style are...
1) Binding Commands (Assignment Statements)
2) Conditional Commands (Selectors)
3) Repetition
4) IO Commands
IF - THEN (ELSE) STATEMENT:
EX 1: Program to read two integers and display the
larger of the two.
int a = IO.read_int();
int b = IO.read_int();
IF: if (a > b)
{
THEN: IO.println(a)
}
ELSE: else
{
IO.println(b);
}
EX 2: Program to read two Integers and display the word
"OK" if they are not equal.
int a = IO.read_int();
int b = IO.read_int();
IF: if (a != b)
{
THEN: IO.print("OK");
IO.rointln();
}
MULTIWAY IF:
Read One Integer and Display
__
"Zero" |
"Negative" |- Depending on the Integer
"Positive"__|
int a = IO.read_int();
IF: if (a > 0)
{
IO.println("Positive");
}
ELSE: else if (a < 0)
{
IO.println ("Negative";
}
ELSE: else
{
IO.println ("Zero");
BAD CODE - NESTED IF's:
Read 3 integers and display them in order,
from low to high.
// Read the Integers
int a = IO.read_int();
int b = IO.read_int();
int c = IO.read_int();
IF: if (a < b)
{
if (a < c)
{
IO.println(a);
{
if (b < c)
{
IO.println (b); IO.println(c);
}
else
IO.println(c); IO,println(b);
BAD CODE - MULTIWAY IF w. ABSTRACTION
if (less(a,b,c)
{
IO.println(a + " " + b + " " + c);
}
else if (less(a,c,b))
{
IO.println(a + " " + c + " " + b);
}
... (Six Times!)
BAD CODE - BOOLEAN NESTED IF's:
static private boolean less(int x,int y,int z)
{
if (x < y)
{
if (y < z)
{
return True;
}
}
return False;
}
==========================================================+
1234567890123456789212345678931234567894123456789512345678+
|
|
|