-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariable.java
More file actions
107 lines (94 loc) · 5.03 KB
/
Variable.java
File metadata and controls
107 lines (94 loc) · 5.03 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************
* Variable Class *
* *
* PROGRAMMER: Emily Culp *
* COURSE: CS340 - Programming Language Design *
* DATE: 11/12/2024 *
* REQUIREMENT: Store variable details for the interpreter *
* *
* DESCRIPTION: *
* The Variable class represents a variable with a name, value, *
* and unique ID. It provides getter and setter methods to access *
* and modify the value of the variable, ensuring the variable's *
* name and ID remain immutable. *
* *
* COPYRIGHT: This code is copyright (C) 2024 Emily Culp and Dean *
* Zeller. *
* *
* CREDITS: This code was written with the help of ChatGPT. *
*******************************************************************/
public class Variable {
private final String name; // Variable name
private int value; // Variable value
private final int id; // Variable ID
/**********************************************************
* CONSTRUCTOR: Variable(String name, int value, int id) *
* DESCRIPTION: *
* Initializes a new Variable object with the specified *
* name, value, and ID. *
* PARAMETERS: *
* String name - the name of the variable *
* int value - the initial value of the variable *
* int id - the unique ID assigned to the variable *
**********************************************************/
public Variable(String name, int id) {
this.name = name;
this.id = id;
}
/**********************************************************
* METHOD: Variable(String name, int value, int id) *
* DESCRIPTION: Constructor for creating a new Variable *
* object with a specified name, value, and ID. *
* PARAMETERS: *
* String name - The name of the variable. *
* int value - The initial value of the variable. *
* int id - A unique identifier for the variable. *
* RETURN VALUE: None (This is a constructor method) *
* EXCEPTIONS: None *
**********************************************************/
public Variable(String name, int value, int id) {
this.name = name;
this.value = value;
this.id = id;
}
/**********************************************************
* METHOD: getName() *
* DESCRIPTION: *
* Retrieves the name of the variable. *
* RETURN VALUE: *
* String - the name of the variable *
**********************************************************/
public String getName() {
return name;
}
/**********************************************************
* METHOD: getValue() *
* DESCRIPTION: *
* Retrieves the current value of the variable. *
* RETURN VALUE: *
* int - the current value of the variable *
**********************************************************/
public int getValue() {
return value;
}
/**********************************************************
* METHOD: setValue(int value) *
* DESCRIPTION: *
* Updates the value of the variable. *
* PARAMETERS: *
* int value - the new value to assign *
**********************************************************/
public void setValue(int value) {
this.value = value;
}
/**********************************************************
* METHOD: getId() *
* DESCRIPTION: *
* Retrieves the unique ID of the variable. *
* RETURN VALUE: *
* int - the ID of the variable *
**********************************************************/
public int getId() {
return id;
}
}