| <<O>> Difference Topic MethcallIntermediateTwoExample (r1.2 - 30 Aug 2003 - IsaacGouy) |
| Changed: | |
| < < | class NthToggle? extends Toggle { int count_max = 0; int counter = 0; |
| > > | class NToggle extends Toggle { int toggleTrigger = 0; int count = 0; |
| Changed: | |
| < < | public NthToggle?(boolean start_state, int max_counter) { |
| > > | public NToggle(boolean start_state, int trigger) { |
| Changed: | |
| < < | this.count_max = max_counter; this.counter = 0; |
| > > | this.toggleTrigger = trigger; this.count = 0; |
| Changed: | |
| < < | public NthToggle? activate() { |
| > > | public NToggle activate() { |
| Changed: | |
| < < | if (this.counter >= this.count_max) { |
| > > | if (this.count >= this.toggleTrigger) { |
| Changed: | |
| < < | this.counter = 0; |
| > > | this.count = 0; |
| Changed: | |
| < < | NthToggle? ntoggle = new NthToggle?(true, 3); |
| > > | NToggle ntoggle = new NToggle(true, 3); |
| <<O>> Difference Topic MethcallIntermediateTwoExample (r1.1 - 30 Aug 2003 - IsaacGouy) |
| Added: | |
| > > |
%META:TOPICINFO{author="IsaacGouy" date="1062255213" format="1.0" version="1.1"}%
%META:TOPICPARENT{name="CodeExamples"}%
/* Please try the BeginnerExamples before the IntermediateExamples
Put this code in directory methcall_intermediatetwo
Compile the Nice Toggle class: NiceToggleExample
To compile:
javac methcall.java
To run:
java methcall 10
*/
import java.io.*;
import java.util.*;
import java.text.*;
import toggles.*; // Nice Toggle class
class NthToggle extends Toggle {
int count_max = 0;
int counter = 0;
public NthToggle(boolean start_state, int max_counter) {
super(start_state);
this.count_max = max_counter;
this.counter = 0;
}
public NthToggle activate() {
this.counter += 1;
if (this.counter >= this.count_max) {
this.state = !this.state;
this.counter = 0;
}
return(this);
}
}
public class methcall {
public static void main(String args[]) throws IOException {
int n = Integer.parseInt(args[0]);
boolean val = true;
Toggle toggle = new Toggle(val);
for (int i=0; i<n; i++) {
toggle = dispatch.activate(toggle);
val = dispatch.value(toggle);
}
System.out.println((val) ? "true" : "false");
val = true;
NthToggle ntoggle = new NthToggle(true, 3);
for (int i=0; i<n; i++) {
ntoggle = ntoggle.activate();
val = dispatch.value(ntoggle);
}
System.out.println((val) ? "true" : "false");
}
}
-- IsaacGouy - 30 Aug 2003 |
| Topic MethcallIntermediateTwoExample . { View | Diffs | r1.2 | > | r1.1 | More } |
|
Revision r1.1 - 30 Aug 2003 - 14:53 GMT - IsaacGouy Revision r1.2 - 30 Aug 2003 - 15:30 GMT - IsaacGouy |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |