/* 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 NToggle extends Toggle {
int toggleTrigger = 0;
int count = 0;
public NToggle(boolean start_state, int trigger) {
super(start_state);
this.toggleTrigger = trigger;
this.count = 0;
}
public NToggle activate() {
this.counter += 1;
if (this.count >= this.toggleTrigger) {
this.state = !this.state;
this.count = 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;
NToggle ntoggle = new NToggle(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 . { Edit | Attach | Ref-By | Printable | Diffs | r1.2 | > | r1.1 | More } |
|
Revision r1.2 - 30 Aug 2003 - 15:30 GMT - IsaacGouy Parents: WebHome > CodeExamples |
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. |