Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will create 7 classes: (1) An ABSTRACT class Operator that has - a private S

ID: 3630156 • Letter: Y

Question

You will create 7 classes:

(1) An ABSTRACT class Operator that has
- a private String called name
- a public abstract method performOperation. parameters: two doubles. return type: double
- a public method getName that returns the name
- a public equals method. parameter: an Operator object. return type: boolean
+ This should return true if the names match.

(2-5): Classes Add, Subtract, Multiply, Divide, which all EXTEND the Operator class
- These will each implement the performOperation method according to its name.
+ E.g., the Add.performOperation method will return the sum of the two double parameters.
- Each constructor should take no parameters. Instead, use super to pass in the name of the operator (e.g., "Add").

(6): The Calculator class that has
- a private instance variable called operators that is an array of Operator objects.
- This array should be set using the Calculator constructor
- A calculate method. parameter: double array called values. return type: double
+ The calculate method uses the operators instance variable to perform calculations
on the values array in order.
FOR EXAMPLE: If the operators array contains Add, Subtract, and Multiply objects,
and the values array contains {4, 5, 6, 7}, then the calculate method should compute:
((4 + 5) - 6)*7
therefore, the calculate method should return 21.
NOTE: If there are too few or too many elements in the value array, return Double.NEGATIVE_INFINITY.
- An equals method. parameter: A Calculator object called c. return type: boolean
+ This should return true if all of the Operator objects in c are equal to all the Operator
objects in this Calculator.

(7) A class called Main that has:
- a testCalculator method. parameters: Calculator called c, double array called values, double called expected
+ This method should use c to perform calculations on the values array. If the result equals expected, return
true and the test passes. Otherwise, return false.
- a main method: You should call the testCalculated method for a number of different inputs to
ensure that your Calculator is working. Remember to test the "corner-cases".

I know this is a lot, but this is due tomorrow and I just can't figure it out :/

This is what I have so far:


public abstract class Operator {

private String name;


abstract public double performOperation(double x, double y);

public String getName() {
    return name;
}


public boolean equals(Operator n){
    if(n instanceof Operator){
    }
        return name.equals(name);
   
}
}




public class Add extends Operator {

public Add(){
    super.getName();
}

public double performOperation(double x, double y) {
    return x +  y;
    }
}




public class Subtract extends Operator {
   
   
public Subtract(){
    super.getName();
}

public double performOperation(double x, double y) {
    return x-y;
    }
}



public class Multiply extends Operator {
       
public Multiply(){
    super.getName();
    }

public double performOperation(double x, double y) {
    return x*y;
    }
}


public class Divide extends Operator {
    String n;

public Divide(){
    super.getName();
   
    }

public double performOperation(double x, double y) {
    return x/y;
    }
}


public class Calculator {
private Operator[] operators;

public Calculator(Operator[] op){
    Operator [] calculators = op;
}

public static double calculate(double [] values){
    for (double i = 0; i < values.length; i++){
        n.performOperation(values);
    }
    if ((values.length > values.length) ^ (values.length < values.length)){
    return Double.NEGATIVE_INFINITY;;
   
}
}

boolean equals(Calculator op){
if (op instanceof Calculator){
}
if (op.equals(op)){
    return true;
}
return false;
}


}



public class Main {

public static boolean testCalculator(Calculator c, double [] values, double expected){
    c.calculate(values);
    if (c.equals(expected)) {
    }
        return true;

}

}



I know I haven't done much, but I'm really confused. Lifesaver guaranteed if your code works! :)



Explanation / Answer

//Operator.java public abstract class Operator { private String name; abstract public double performOperation(double n1, double n2); public Operator(String opname) { name= opname; } public String getName() { return name; } public boolean equals(Operator op) { return op.toString().equals(toString()); } } //Add.Java public class Add extends Operator { public Add() { super("Add"); } @Override public double performOperation(double n1, double n2) { return n1+n2; } } //Subtract.Java public class Subtract extends Operator { public Subtract() { super("Subtract"); } @Override public double performOperation(double n1, double n2) { return n1-n2; } } //Multiply.Java public class Multiply extends Operator { public Multiply() { super("Multiply"); } @Override public double performOperation(double n1, double n2) { return n1*n2; } } //Divide.Java public class Divide extends Operator { public Divide() { super("Divide"); } @Override public double performOperation(double n1, double n2) { return n1/n2; } } //Calculator.Java public class Calculator { private Operator[] opearators; public Calculator(Operator[] op) { opearators = op; } public double calculate(double[] values) { double result = 0; if(opearators.length == (values.length - 1)) { for(int i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote