class Fraction {
int frac;//fraction
int sec;//section
Fraction( int fraction, int section) {// fraction/section
this.frac = fraction;
this.sec = section;
}
Fraction( int fraction) {// fraction/1
this.frac = fraction;
this.sec = 0;
}
void display() {
println( this.frac + "/" + this.sec);
}
void plus (Fraction b) {
int frac;
int sec;
if (this.sec == b.sec) {
frac = this.frac + b.frac;
sec = this.sec;
} else {
top = (this.frac * b.sec) + (b.frac * this.sec);
sec = this.sec * b.sec;
}
}
void minus(Fraction b) {
int frac;
int sec;
if (this.sec == b.sec) {
frac = this.frac - b.frac)
sec = this.sec ;
} else {
frac = (this.frac * b.sec) - (b.frac * this.sec);
sec = this.sec * b.sec;
}
}
void multiply(Fraction b) {
int frac;
int sec;
top = this.frac * b.frac
sec = this.sec * b.sec
}
void divide(Fraction b) {
println(this.frac * b.sec+ "/" + this.sec * b.frac);
}
}
void setup() {
Fraction a; // Create object
Fraction b;
a = new Fraction(1, 2); // 1/2
b = new Fraction(2, 3);
a.plus(b); // a + b
a.minus(b); // a - b
a.multiply(b); // a * b
a.divide(b); // a / b
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น