-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecordManagment.java
More file actions
40 lines (32 loc) · 1.13 KB
/
Copy pathRecordManagment.java
File metadata and controls
40 lines (32 loc) · 1.13 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
/*The functionality of this Java program is to prompt the user to input a name and a year, create a record object with these
values, validate the year within a specified range (1996-2023), and add the record to a list if it meets the criteria.*/
import java.util.ArrayList;
import java.util.Scanner;
class Record {
int year;
String name;
ArrayList<Record> arr = new ArrayList<>();
void addRecord(Record r) throws Exception {
if (r.year < 1996 || r.year > 2023) {
throw new Exception("Invalid year");
} else {
arr.add(r);
}
}
void printRecord() {
for (Record r : arr) {
System.out.println(r);
}
}
}
public class RecordManagement {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
Record r = new Record();
System.out.print("Enter the name: ");
r.name = scanner.nextLine();
System.out.print("Enter the year: ");
r.year = scanner.nextInt();
r.addRecord(r);
}
}