Fraction Answer;
int x = 1;
int y = 2;
int a = 3;
int b = 4;
Answer = new Fraction (x, y, a, b);
println ("("+x+"/"+y+" + "+a+"/"+b+") = "+Answer.Addition());
println ("("+x+"/"+y+" - "+a+"/"+b+") = "+Answer.Subtraction());
println ("("+x+"/"+y+" x "+a+"/"+b+") = "+Answer.Multiple());
println ("("+x+"/"+y+" / "+a+"/"+b+") = "+Answer.Division());
}
void draw () {
}
class Fraction {
int x;
int y;
int a;
int b;
Fraction (int x, int y, int a, int b) {
this.x = x;
this.y = y;
this.a = a;
this.b = b;
}
float Addition () {
float value1 = ((this.x*this.b)+(this.y*this.a));
float value2 = (this.y*this.b);
float add_result = value1/value2;
return add_result;
}
float Subtraction () {
float value1 = ((this.x*this.b)-(this.y*this.a));
float value2 = (this.y*this.b);
float sub_result = value1/value2;
return sub_result;
}
float Multiple () {
float value1 = (this.x*this.a);
float value2 = (this.y*this.b);
float mul_result = value1/value2;
return mul_result;
}
float Division () {
float value1 = (this.x*this.b);
float value2 = (this.y*this.a);
float div_result = value1/value2;
return div_result;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น