-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.java
More file actions
56 lines (48 loc) · 1.4 KB
/
Variable.java
File metadata and controls
56 lines (48 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @author Rakith (Jay) Jayewardene
* Creates a class named Variable that extends Function
*/
public class Variable extends Function{
/* Stores the inputValue */
private double inputValue;
/**
* A method that takes a double named inputValue as input and returns the value
* @return the inputValue as a double */
@Override
public double value(double inputValue) {
return inputValue;
}
/**
* A method that takes no input and throws an Unsupported Operation Exception
*/
@Override
public double value() {
throw new UnsupportedOperationException();
}
/**
* A method that takes no input and takes the derivative of the variable
* @return the derivative of the variable in type Function
*/
@Override
public Function derivative() {
return new Number(1);
}
/**
* A method that takes no input and converts the variable to a String
* @return the String representation of the variable
*/
@Override
public String toString() {
return "x";
}
/* A method that takes an input Object called function and compares it to a different variable
* @return true if the object is equal to the variable and returns false if it does not
*/
@Override
public boolean equals(Object function) {
if(function instanceof Variable) {
return true;
}
return false;
}
}