-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperand.java
More file actions
79 lines (73 loc) · 2.05 KB
/
Operand.java
File metadata and controls
79 lines (73 loc) · 2.05 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Operand.java - Token, holds integer operands
//
// Kurt Schmidt
// 3/07
//
// javac 1.6.0, on Linux version 2.6.18.6 (gcc version 3.4.6 (Gentoo
// 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9))
//
// EDITOR: tabstop=2, cols=80
//
// NOTES:
// Tokens come in 2 flavors:
// operands (only integers here)
// operators (just +, -, *, /, exponentiation, parenthesis)
//
// This is so you can have a single container (Vector, ArrayList, whatever)
// that holds an entire expression (Token).
//
/**
* Represents an operand, i.e. a positive number upon which arithmetical
* operations are performed. Modified by me (Allison Schinagle) to conform
* with the Google Java style guide (more or less; 4 spaces instead of 2), and
* added documentation, and a toString method. Inherits from Token, since an
* Operand is a kind of token.
*/
public class Operand extends Token {
/**
* The value of the operand.
*/
protected int val;
/**
* Inherited from the Token class. This is the Operand class, so it is not
* an operator, so this returns false.
*
* @return false because this is not the Operator class
*/
public boolean isOperator() {
return false;
}
/**
* Inherited from the Token class. This is the Operand class, so it is an
* operand, so this returns true.
*
* @return true because this is the Operand class
*/
public boolean isOperand() {
return true;
}
/**
* Retrieves the value that the instance of this class is representing.
*
* @return val
*/
public int getVal() {
return this.val;
}
/**
* Constructs an Operand object. val is set to the given value, v.
*
* @param v the value that this Operand will represent
*/
public Operand(int v) {
this.val = v;
}
/**
* Returns a representation of this Operand as a String.
*
* @return a String representing the value of this Operand
*/
public String toString() {
return (new Integer(val)).toString();
}
}