blob: da4a051689c3be9ce8819be8d96b823d0398a3bb (
plain)
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
|
// Nik Johnson
// 2-24-2024
// TA: Andy Ruan
/*
Defining an object called Error, which has the fields:
code: the errors code, represented by an int
lineNumber: the line where the error occurred
message: a description of the error
*/
public class Error {
private int code;
private int lineNumber;
private String message;
// construct an error with its fields
public Error(int code, int lineNumber, String message) {
this.code = code;
this.lineNumber = lineNumber;
this.message = message;
}
// format an error and its information nicely
public String toString() {
return ("(Line: " + lineNumber + ") " + "has error code " + code + "\n" + message);
}
// return line where the error occurs
public int getLineNumber() {
return this.lineNumber;
}
// return the error code (a number)
public int getCode() {
return this.code;
}
// return the errors description
public String getMessage() {
return this.message;
}
}
|