Title: Incremental Coding
1Incremental Coding
- Incremental coding is good!
- Uses divide and conquer to minimize problem scope
- Helps testing tremendously!
- So what is it?
- It is a methodology for writing your program
- Two types
- Top down
- Bottom up
2Incremental Coding Top Down
- The top down approach begins with the general and
works towards the specifics - Start with a skeleton class
- Add small details a little at a time
- Test after each addition!
3Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) double
result result fraction data1 return
result // this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1() d
ouble f e2.getDataFraction(0.4) //end
of Example class
4Incremental Coding
- /
- Title Example.java
- Files Example.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
//end of Example class
5Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
-
//end of Example
class
6Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- // code will go here
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) //
code will go here // this is the main
method public static void main(String
args) // code will go here //end
of Example class
7Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- // code will go here
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) //
code will go here // this is the main
method public static void main(String
args) // code will go here //end
of Example class
8Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) //
code will go here // this is the main
method public static void main(String
args) // code will go here //end
of Example class
9Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) double
result result fraction data1 return
result // this is the main method public
static void main(String args) // code
will go here //end of Example
class
10Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) double
result result fraction data1 return
result // this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1() d
ouble f e2.getDataFraction(0.4) //end
of Example class
11Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) double
result result fraction data1 return
result // this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1() d
ouble f e2.getDataFraction(0.4) //end
of Example class
12Incremental Coding Bottom up
- The Bottom up approach begins with specific
details slowly combines them into the program - Start with a skeleton class
- Code individual functional parts of the program
- Slowly combine functional parts
- Test after each combination!
13Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
-
//end of Example
class
14Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
// this is the main method public static
void main(String args) Example e1 new
Example(1,2) Example e2 new
Example(3,4) //end of Example
class
15Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) //end of Example
class
16Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) //end of Example
class
17Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public static
void main(String args) Example e1 new
Example(1,2) Example e2 new
Example(3,4) int x e1.getData1()
//end of Example class
18Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public static
void main(String args) Example e1 new
Example(1,2) Example e2 new
Example(3,4) int x e1.getData1()
//end of Example class
19Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public static
void main(String args) Example e1 new
Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 //end of Example class
20Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public static
void main(String args) Example e1 new
Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1()
//end of Example class
21Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is the main method public static
void main(String args) Example e1 new
Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1() d
ouble f e2.getDataFraction(0.4) //end
of Example class
22Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) double
result result fraction data1 return
result // this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1() d
ouble f e2.getDataFraction(0.4) //end
of Example class
23Incremental Coding
- /
- Title Card.java
- Files Card.java
- Author Peter McClone
- CS Login mc-clone
/ - // no import statements
- public class Example
- // these are instance variables
- private int data1
- public int data2
- // this is the constructor
- public Example(int first, int second)
- data1 first
- data2 second
-
// this is another instance method // this
method computes a fraction of data1 public
double getDataFraction(double fraction) double
result result fraction data1 return
result // this is the main method public
static void main(String args) Example e1
new Example(1,2) Example e2 new
Example(3,4) int x e1.getData1() int y
e2.data2 int z e1.data2 e2.getData1() d
ouble f e2.getDataFraction(0.4) //end
of Example class
24Incremental Coding