20 กันยายน 2556

Class

void setup(){
  size(400,250);
  background(111);
  Fraction f = new Fraction(2,7);
  Fraction g = new Fraction(4,9);
  f.add(3);
  text("="+f.toString(),195,140);
}

class Fraction{
  int n;
  int d;
  Fraction(int a,int b){
    n = a; //this.n = a
    d = b;
  }
  void add(int z){
    text(this.n+"/"+this.d,195,100);
    text(z,195,120);
    this.n = this.d*z+this.n;
  }
   
  String toString(){
    String s = this.n+"/"+this.d;
    return s;
  }
  void reciprocal(){
    int temp;
    temp = n;
    n = d;
    d = temp;
  }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น