Skip to content

Commit c2abf4d

Browse files
Update README.md
1 parent e724327 commit c2abf4d

File tree

1 file changed

+136
-76
lines changed

1 file changed

+136
-76
lines changed

README.md

Lines changed: 136 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,136 @@
1-
# Java Advanced: Exception Handling & Collections (Task 4)
2-
3-
This repository contains Java programs demonstrating advanced concepts such as exception handling and the use of collection classes. The project includes solutions to five tasks (Q1 to Q5) focusing on custom exceptions, array handling, HashMap operations, and stack implementation.
4-
5-
## Project Structure
6-
7-
- **Student.java**: Implements the `Student` class with exception handling for age and name validation (Q1).
8-
- **AgeNotWithinRangeException.java**: Custom exception for invalid student age (Q1).
9-
- **NameNotValidException.java**: Custom exception for invalid student name (Q1).
10-
- **Voter.java**: Implements the `Voter` class with age validation using exceptions (Q2).
11-
- **QuestionThree.java**: Handles weekday array with exception handling for invalid indices (Q3).
12-
- **QuestionFour.java**: Implements a HashMap for student names and grades with methods to add, remove, and display (Q4).
13-
- **QuestionFive.java**: Implements a stack for integers using collection classes with push, pop, and isEmpty methods (Q5).
14-
- **1.c.png, 1.d.png, 2.a.png, 2.b.png, 3.a.png, 3.b.png, 3.c.png, 4.a.png, 4.b.png, 4.c.png, 4.d.png, 5.png**: Screenshots of the code implementations for each task.
15-
16-
## Tasks Overview
17-
18-
### Q1: Student Management System with Exception Handling
19-
- **Student Class**: Represents a student with attributes `rollNo`, `name`, `age`, and `course`, initialized via a parameterized constructor.
20-
- **Exceptions**:
21-
- Throws `AgeNotWithinRangeException` if the age is not between 15 and 21.
22-
- Throws `NameNotValidException` if the name contains numbers or special symbols.
23-
- Custom exception classes are defined to handle these scenarios.
24-
25-
### Q2: Voter Class with Age Validation
26-
- **Voter Class**: Contains attributes `voterId`, `name`, and `age`, initialized via a parameterized constructor.
27-
- Throws an exception (checked or unchecked) if the age is less than 18, with the message "invalid age for voter".
28-
29-
### Q3: Weekday Array with Exception Handling
30-
- Stores weekday names in an array starting with "Sunday" at index 0.
31-
- Accepts a day position from the user and prints the corresponding day name.
32-
- Handles `ArrayIndexOutOfBoundsException` for indices outside the range 0-6, displaying a proper error message.
33-
34-
### Q4: Student Grades HashMap
35-
- Uses a `HashMap` to store student names (keys) and grades (integer values).
36-
- Provides methods to:
37-
- Add a new student and grade.
38-
- Remove a student.
39-
- Display a student’s grade by name.
40-
41-
### Q5: Stack Implementation with Collection Classes
42-
- Uses a collection class to store integers in a stack.
43-
- Implements methods to:
44-
- Push elements onto the stack.
45-
- Pop elements from the stack.
46-
- Check if the stack is empty.
47-
48-
## How to Run
49-
50-
1. **Clone the Repository**:
51-
```bash
52-
git clone https://github.com/thesoulseizure/task-4.git
53-
```
54-
2. **Navigate to the Project Directory**:
55-
```bash
56-
cd task-4
57-
```
58-
3. **Compile the Java Files**:
59-
```bash
60-
javac *.java
61-
```
62-
4. **Run the Desired Program**:
63-
- For Q1: `java Student`
64-
- For Q2: `java Voter`
65-
- For Q3: `java QuestionThree`
66-
- For Q4: `java QuestionFour`
67-
- For Q5: `java QuestionFive`
68-
69-
## Requirements
70-
71-
- Java Development Kit (JDK) 8 or higher.
72-
- A terminal or IDE to compile and run Java programs.
73-
74-
## Screenshots
75-
76-
The repository includes screenshots (1.c.png to 5.png) that show the code implementations for each task. Refer to these images to view the solutions visually.
1+
# Java Advanced: Exception Handling & Collections
2+
3+
This repository showcases **advanced Java concepts**, focusing on **custom exceptions**, **robust error handling**, and **Java Collections Framework** usage.
4+
It includes **five fully implemented tasks (Q1–Q5)** accompanied by code screenshots for clarity and reference.
5+
6+
---
7+
8+
## 📁 Project Structure
9+
10+
```
11+
├── AgeNotWithinRangeException.java # Custom exception for invalid student age
12+
├── NameNotValidException.java # Custom exception for invalid name
13+
├── Student.java # Student class using custom exceptions (Q1)
14+
├── Voter.java # Voter class with age validation (Q2)
15+
├── QuestionThree.java # Weekday array + exception handling (Q3)
16+
├── QuestionFour.java # HashMap for student grades (Q4)
17+
├── QuestionFive.java # Stack implementation using collections (Q5)
18+
├── Screenshots/
19+
│ ├── 1.a.png 1.b.png 1.c.png 1.d.png
20+
│ ├── 2.a.png 2.b.png
21+
│ ├── 3.a.png 3.b.png 3.c.png
22+
│ ├── 4.a.png 4.b.png 4.c.png 4.d.png
23+
│ └── 5.png
24+
└── README.md
25+
```
26+
27+
---
28+
29+
## 🧩 Task Overviews
30+
31+
### **Q1 — Student Management System (Custom Exceptions)**
32+
Implements:
33+
- `Student` class with:
34+
- `rollNo`, `name`, `age`, `course`
35+
- Custom exceptions:
36+
- **AgeNotWithinRangeException** → age must be between **15–21**
37+
- **NameNotValidException** → name must contain only letters
38+
- Validates input using constructor-based rules.
39+
40+
📸 **Screenshots:**
41+
![1.c](1.c.png)
42+
![1.d](1.d.png)
43+
44+
---
45+
46+
### **Q2 — Voter Age Validation**
47+
`Voter` class validates:
48+
- Age must be **18 or above**
49+
- Throws an exception for invalid age
50+
51+
📸 **Screenshots:**
52+
![2.a](2.a.png)
53+
![2.b](2.b.png)
54+
55+
---
56+
57+
### **Q3 — Weekday Array + Exception Handling**
58+
- Stores weekday names in an array (index 0 = Sunday)
59+
- Accepts user index input
60+
- Handles:
61+
- **ArrayIndexOutOfBoundsException**
62+
- Prints helpful error message
63+
64+
📸 **Screenshots:**
65+
![3.a](3.a.png)
66+
![3.b](3.b.png)
67+
![3.c](3.c.png)
68+
69+
---
70+
71+
### **Q4 — Student Grades Using HashMap**
72+
Implements:
73+
- Add student + grade
74+
- Remove student
75+
- Display grade by name
76+
77+
Uses Java **HashMap** to store key–value pairs.
78+
79+
📸 **Screenshots:**
80+
![4.a](4.a.png)
81+
![4.b](4.b.png)
82+
![4.c](4.c.png)
83+
![4.d](4.d.png)
84+
85+
---
86+
87+
### **Q5 — Stack Implementation Using Collections**
88+
Implements:
89+
- `push()`
90+
- `pop()`
91+
- `isEmpty()`
92+
93+
Built using a Java **Stack** or similar collection class.
94+
95+
📸 **Screenshot:**
96+
![5](5.png)
97+
98+
---
99+
100+
## ▶️ How to Run
101+
102+
### **1. Clone the Repository**
103+
```bash
104+
git clone https://github.com/thesoulseizure/task-4.git
105+
cd task-4
106+
```
107+
108+
### **2. Compile All `.java` Files**
109+
```bash
110+
javac *.java
111+
```
112+
113+
### **3. Run Any Task**
114+
115+
| Task | Command |
116+
|------|----------|
117+
| Q1 — Student | `java Student` |
118+
| Q2 — Voter | `java Voter` |
119+
| Q3 — Weekday Array | `java QuestionThree` |
120+
| Q4 — HashMap Grades | `java QuestionFour` |
121+
| Q5 — Stack | `java QuestionFive` |
122+
123+
---
124+
125+
## 📌 Requirements
126+
- **JDK 8 or higher**
127+
- Any IDE or terminal that can compile and run Java programs
128+
129+
---
130+
131+
## 📄 License
132+
This project is for **educational purposes** and demonstrates core Java error-handling & collections concepts.
133+
134+
---
135+
136+

0 commit comments

Comments
 (0)