import java.applet.Applet; import java.awt.event.*; import java.awt.*; /**This class does the basic arithmetic of complex numbers */ public class GaussianInteger { int x,y; public GaussianInteger() { this.x=0; this.y=0; } public GaussianInteger(int x,int y) { this.x=x; this.y=y; } public GaussianInteger(GaussianInteger g) { this.x=g.x; this.y=g.y; } /**This operation only makes sense when we are averaging even numbers.**/ /**printout**/ public void print() { System.out.println("Gaussian: "+this.x+" "+this.y); } public static GaussianInteger average(GaussianInteger g1,GaussianInteger g2) throws ProofException { int test=0; if(g1.x%2==1) test=1; if(g1.y%2==1) test=1; if(g2.x%2==1) test=1; if(g2.y%2==1) test=1; if(test==1) throw new ProofException("Gaussian: odd integers now allowed."); int x=(g1.x+g2.x)/2; int y=(g1.y+g2.y)/2; GaussianInteger g=new GaussianInteger(x,y); return(g); } public static GaussianInteger convert(Complex z,int n) { double xx=z.x*Math.pow(2,n); double yy=z.y*Math.pow(2,n); int x=(int)(xx); int y=(int)(yy); if(Math.abs(x-xx)>.000000001) System.out.println("warning: Gaussian Integer ill defined"); if(Math.abs(y-yy)>.000000001) System.out.println("warning: Gaussian Integer illdefined"); GaussianInteger g=new GaussianInteger(x,y); return(g); } }