-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment3p3.java
More file actions
52 lines (42 loc) · 1.65 KB
/
Assignment3p3.java
File metadata and controls
52 lines (42 loc) · 1.65 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
import java.util.Scanner;
class CourseFullException extends Exception {
public CourseFullException(String message) {
super(message);
}
}
class PrerequisiteNotMetException extends Exception {
public PrerequisiteNotMetException(String message) {
super(message);
}
}
class Assignment3p3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String course = "Advanced Java";
String prerequisite = "Core Java";
boolean prerequisiteCompleted = false;
boolean courseFull = false;
try {
System.out.print("Enroll in Course: ");
String selectedCourse = scanner.nextLine();
if (!selectedCourse.equals(course)) {
System.out.println("Course not available.");
return;
}
System.out.print("Prerequisite: ");
String selectedPrerequisite = scanner.nextLine();
if (!selectedPrerequisite.equals(prerequisite)) {
throw new PrerequisiteNotMetException("Error: PrerequisiteNotMetException - Complete Core Java before enrolling in Advanced Java.");
}
if (courseFull) {
throw new CourseFullException("Error: CourseFullException - The course is full.");
}
System.out.println("Enrollment Successful for " + course);
} catch (PrerequisiteNotMetException | CourseFullException e) {
System.out.println(e.getMessage());
} finally {
System.out.println("Thank you for using the university enrollment system.");
scanner.close();
}
}
}