-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber.java
65 lines (57 loc) · 1.65 KB
/
Number.java
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
57
58
59
60
61
62
63
64
65
/**
* @author Rakith (Jay) Jayewardene
* Creates a class named Number that extends Function
*/
public class Number extends Function{
/* Stores the inputValue */
private double inputValue;
/**
* A constructor that initializes an input double named inputValue
* @param inputValue
*/
public Number(double inputValue) {
this.inputValue = 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 this.inputValue;
}
/**
* A method that takes no input and returns the value
* @return the inputValue as a double */
@Override
public double value() {
return this.inputValue;
}
/**
* A method that takes no input and takes the derivative of the number
* @return the derivative of the number in type Function
*/
@Override
public Function derivative() {
return new Number(0);
}
/**
* A method that takes no input and converts the number to a String
* @return the String representation of the number
*/
@Override
public String toString() {
return "" +this.inputValue;
}
/* A method that takes an input Object called function and compares it to a different number
* @return true if the object is equal to the number and returns false if it does not
*/
@Override
public boolean equals(Object function) {
if(function instanceof Number) {
if (this.inputValue == ((Number)(function)).value()) {
return true;
}
}
return false;
}
}