Skip to content
Snippets Groups Projects
Commit af3e41c0 authored by MAAZOUZ Ilyas's avatar MAAZOUZ Ilyas
Browse files

kamihamihagh

parent 1ce5eadf
Branches
No related tags found
No related merge requests found
Pipeline #19468 failed
import static java.lang.Math.abs;
public class AbsoluteValue implements Formula{
private String var;
private double val;
public AbsoluteValue(Formula X){
this.var= "|"+X.asString()+"|";
this.val=abs(X.asValue());
}
public String asString() {
return this.var;
}
public double asValue() {
return this.val;
}
}
public class PostfixsubstringFilter implements StringFilter{
private int n;
public PostfixsubstringFilter(int nombre){
this.n=nombre;
}
public String filter(String chaine){
int x=chaine.length();
return chaine.substring(n,x);
}
}
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
public class Power implements Formula{
private String var;
private double val;
public Power(Formula X,int i){
this.var= X.asString()+"^"+i;
this.val=pow(X.asValue(),i);
}
public String asString() {
return this.var;
}
public double asValue() {
return this.val;
}
}
......@@ -2,9 +2,13 @@ public class Product implements Formula {
private double Prod;
private String formule;
public Product (Variable X , Variable Y){
Prod=X.getVal()*Y.getVal();
formule=X.getChar()+"*"+Y.getChar();
public Product (Formula[] X ){
this.formule="";
for (int i = 0; i < X.length; i++) {
this.Prod+= X[i].asValue();
this.formule +=X[i].asString()+"+";
}
this.formule=this.formule.substring(0,this.formule.length()-1);
}
public String asString() {
......@@ -15,4 +19,6 @@ public class Product implements Formula {
public double asValue() {
return Prod;
}
}
public class Square implements Formula{
private String var;
private double val;
public Square(Formula X){
this.var= X.asString()+"²";
this.val=Math.pow(X.asValue(),2);
}
public String asString() {
return this.var;
}
public double asValue() {
return this.val;
}
}
\ No newline at end of file
import static java.lang.Math.abs;
import static java.lang.Math.sqrt;
public class SquareRoot implements Formula{
private String var;
private double val;
public SquareRoot(Formula X){
this.var= "√"+X.asString();
this.val=sqrt(X.asValue());
}
public String asString() {
return this.var;
}
public double asValue() {
return this.val;
}
}
public class Sum implements Formula{
private double sommation;
private String formule;
public Sum (Formula[] X) {
this.formule="";
for (int i = 0; i < X.length; i++) {
this.sommation += X[i].asValue();
this.formule +=X[i].asString()+"+";
}
this.formule=this.formule.substring(0,this.formule.length()-1);
}
public String asString(){
return this.formule;
}
public double asValue() {
return this.sommation;
}
}
public class Variable {
private char Var;
public class Variable implements Formula {
private String Var;
private double Val;
public Variable(char nomVar,double valeur){
public Variable(String nomVar,double valeur){
this.Var=nomVar;
this.Val=valeur;
}
public double getVal(){
return this.Val;
}
public char getChar(){
return this.Var;
}
public void setVar(double valeur){
this.Val=valeur;
}
public String asString() {
return this.Var;
}
public double asValue() {
return this.Val;
}
}
public class app {
public static void main(String[] args) {
Variable x = new Variable("x", 2.5);
Variable y = new Variable("y", 4);
Formula[] tab= new Variable[2];
tab[0]=x;
tab[1]=y;
Formula formula=new Sum(tab);
System.out.println(formula.asString());
System.out.println(formula.asValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment