├── README.md ├── Task_1_Number_Game.java ├── Task_2_Student_Grade_Calculator.java ├── Task_3_ATM_Interface.java ├── Task_4_StudentCourseRegistrationSystem.java └── Task_5_Student_management_system.java /README.md: -------------------------------------------------------------------------------- 1 | # CodSoft Internship Offer Letter 2 | 3 | ![CodSoft Logo](https://www.codsoft.in/logo.png) 4 | 5 | ## Internship Details 6 | 7 | - **Date:** 14/08/2023 8 | - **ID:** CS07WX43672 9 | 10 | Dear Vinay Kumar, 11 | 12 | Congratulations! We are delighted to offer you the "Java Programming" internship position at **CodSoft**. We are excited about your decision to join our team. 13 | 14 | The internship is scheduled for a duration of 4 weeks, starting from August 15, 2023, to September 15, 2023. This internship is designed to provide you with valuable educational opportunities, focusing on learning, skill development, and gaining practical knowledge. 15 | 16 | ## Internship Expectations 17 | 18 | During the internship, we expect you to engage fully in all assigned tasks, giving your best effort to each one. You will be provided with clear and reasonable instructions that you are required to follow. 19 | 20 | ## Conclusion 21 | 22 | We believe that this internship experience will contribute significantly to your growth. We look forward to working together and assisting you in achieving your career aspirations. 23 | 24 | Best of luck! 25 | 26 | Thank you, 27 | 28 | Founder 29 | CodSoft 30 | 31 | Website: [www.codsoft.in](https://www.codsoft.in) 32 | Email: contact@codsoft.in 33 | 34 | ![ISO 9001-2015 Certified](https://www.codsoft.in/iso-certified.png) 35 | ![MSME Registered](https://www.codsoft.in/msme-registered.png) 36 | 37 | # Task 1: Number Guessing Game 38 | 39 | Welcome to the Number Guessing Game! In this game, you will have the opportunity to guess a random number within a specified range. Try to guess the number correctly within the given number of attempts. Let's see how skilled you are at guessing! 40 | 41 | ## How to Play 42 | 43 | - The game will generate a random number within a specified range, such as 1 to 100. 44 | - You will be prompted to enter your guess for the generated number. 45 | - The game will provide feedback on whether your guess is correct, too high, or too low. 46 | - You will have a limited number of attempts to guess the correct number. 47 | 48 | ## Additional Features 49 | 50 | ### Multiple Rounds 51 | 52 | You have the option to play multiple rounds of the game. After each round, you can decide whether to continue playing or exit the game. 53 | 54 | ### Scoring 55 | 56 | Your score will be calculated based on the number of attempts you took to guess the correct number. The fewer attempts you need, the higher your score will be. 57 | 58 | ## Instructions 59 | 60 | 1. Run the game by executing the provided script. 61 | 2. Follow the prompts to guess the correct number. 62 | 3. After each round, choose whether to play again or exit. 63 | 4. Have fun and test your guessing skills! 64 | 65 | ## Example Gameplay 66 | - Welcome to the Number Guessing Game! 67 | 68 | - Round 1 - Range: 1 to 100 69 | - You have 7 attempts. 70 | 71 | - Enter your guess: 50 72 | - Too low! Try again. 73 | 74 | - Enter your guess: 75 75 | - Too high! Try again. 76 | 77 | - Enter your guess: 63 78 | - Correct! You guessed the number in 3 attempts. 79 | 80 | - Your current score: 3 81 | 82 | - Do you want to play another round? (yes/no): yes 83 | 84 | - Round 2 - Range: 1 to 100 85 | - You have 7 attempts. 86 | 87 | - Enter your guess: 25 88 | - Too low! Try again. 89 | 90 | - Enter your guess: 50 91 | - Too high! Try again. 92 | 93 | - Enter your guess: 38 94 | - Correct! You guessed the number in 3 attempts. 95 | 96 | - Your current score: 6 97 | 98 | - Do you want to play another round? (yes/no): no 99 | 100 | - Thank you for playing! Your final score: 6 101 | 102 | # Task 2: Student Grade Calculator 103 | 104 | Welcome to the Student Grade Calculator! This program allows you to calculate your average percentage and corresponding grade based on the marks obtained in each subject. 105 | 106 | ## How to Use 107 | 108 | 1. Run the program by executing the provided script. 109 | 2. Enter the number of subjects for which you want to calculate the grade. 110 | 3. Enter the marks obtained (out of 100) for each subject. 111 | 4. The program will calculate the total marks, average percentage, and assign a grade based on the average percentage. 112 | 113 | ## Example 114 | 115 | - Enter the number of subjects: 5 116 | - Enter marks obtained in subject 1: 85 117 | - Enter marks obtained in subject 2: 92 118 | - Enter marks obtained in subject 3: 78 119 | - Enter marks obtained in subject 4: 70 120 | - Enter marks obtained in subject 5: 88 121 | 122 | - Total Marks: 413 123 | - Average Percentage: 82.6% 124 | - Grade: B 125 | 126 | ## Grade Scale 127 | 128 | - A: Average Percentage >= 90% 129 | - B: 80% <= Average Percentage < 90% 130 | - C: 70% <= Average Percentage < 80% 131 | - D: 60% <= Average Percentage < 70% 132 | - E: 50% <= Average Percentage < 60% 133 | - F: Average Percentage < 50% 134 | 135 | ## Instructions 136 | 137 | 1. Clone or download this repository to your local machine. 138 | 2. Compile and run the provided Java file using a Java compiler or IDE. 139 | 3. Follow the prompts to input the marks and calculate the grade. 140 | 141 | Have fun using the Student Grade Calculator to determine your average percentage and grade based on your marks! 142 | 143 | 144 | 145 | Note: This program uses a simple grading scale for illustrative purposes. In real-world scenarios, grading scales can vary based on institutions or organizations. 146 | 147 | # Task 3 : ATM Interface 148 | 149 | Welcome to the ATM Interface program! This program simulates a simple ATM interface, allowing users to perform transactions such as checking balance, depositing, and withdrawing funds. 150 | 151 | ## Features 152 | 153 | - Display a menu with options to check balance, deposit, and withdraw funds. 154 | - Perform transactions based on user input. 155 | - Validate user input to ensure accurate transactions. 156 | - Display appropriate messages for successful and failed transactions. 157 | 158 | ## How to Use 159 | 160 | 1. Clone or download this repository to your local machine. 161 | 2. Compile the Java file using a Java compiler or IDE. 162 | 3. Run the compiled program to start the ATM Interface. 163 | 4. Follow the on-screen prompts to interact with the ATM, check balance, deposit, and withdraw funds. 164 | 5. Exit the program when done. 165 | 166 | ## Example Usage 167 | 168 | $ javac Main.java 169 | $ java Main 170 | Enter initial account balance: $1000 171 | ATM Menu: 172 | 1. Check Balance 173 | 2. Deposit 174 | 3. Withdraw 175 | 4. Exit 176 | Select an option: 2 177 | Enter deposit amount: $200 178 | Deposit of $200.0 successful. Current balance: $1200.0 179 | ATM Menu: 180 | 1. Check Balance 181 | 2. Deposit 182 | 3. Withdraw 183 | 4. Exit 184 | Select an option: 3 185 | Enter withdrawal amount: $800 186 | Withdrawal of $800.0 successful. Current balance: $400.0 187 | 188 | 189 | 190 | # Task 4: Student Course Registration System 191 | 192 | Welcome to the Student Course Registration System! This program allows students to register for courses and manage their course schedule. 193 | 194 | ## Features 195 | 196 | - Store course information, including course code, title, description, capacity, and schedule. 197 | - Store student information, including student ID, name, and registered courses. 198 | - Display available courses with details and available slots. 199 | - Allow students to register for courses from the available options. 200 | - Enable students to drop courses they have registered for. 201 | - Interactive console-based user interface. 202 | 203 | ## How to Use 204 | 205 | 1. Clone or download this repository to your local machine. 206 | 2. Compile the Java file(s) using a Java compiler or IDE. 207 | 3. Run the compiled program to start the Student Course Registration System. 208 | 4. Follow the on-screen prompts to interact with the system, including course registration and removal. 209 | 5. Exit the program when done. 210 | 211 | 212 | # Task 5: Student Management System 213 | 214 | Welcome to the Student Management System! This program allows you to manage student information including names, roll numbers, and grades. 215 | 216 | ## Features 217 | 218 | - Add a new student with name, roll number, and grade. 219 | - Remove a student by roll number. 220 | - Search for a student by roll number. 221 | - Display all students' information. 222 | - Interactive console-based user interface. 223 | - Simple and easy-to-use. 224 | 225 | ## How to Use 226 | 227 | - 1. Clone or download this repository to your local machine. 228 | - 2. Compile the Java file using a Java compiler or IDE. 229 | - 3. Run the compiled program to start the Student Management System. 230 | - 4. Follow the on-screen prompts to add, remove, search, and display student information. 231 | - 5. Exit the program when done. 232 | 233 | ## Example Usage 234 | 235 | 236 | ## Student Management System 237 | - 1. Add Student 238 | - 2. Remove Student 239 | - 3. Search Student 240 | - 4. Display All Students 241 | - 5. Exit 242 | - Select an option: 1 243 | 244 | - Enter Name: John Doe 245 | - Enter Roll Number: 123 246 | - Enter Grade: A 247 | 248 | ## Student added successfully. 249 | 250 | - Student Management System 251 | - 1. Add Student 252 | - 2. Remove Student 253 | - 3. Search Student 254 | - 4. Display All Students 255 | - 5. Exit 256 | - Select an option: 3 257 | 258 | ## Enter Roll Number to Search: 123 259 | - Student Found: 260 | - Name: John Doe 261 | - Roll Number: 123 262 | - Grade: A 263 | 264 | ## Student Management System 265 | - 1. Add Student 266 | - 2. Remove Student 267 | - 3. Search Student 268 | - 4. Display All Students 269 | - 5. Exit 270 | ## Select an option: 2 271 | 272 | - Enter Roll Number to Remove: 123 273 | - Student removed successfully. 274 | 275 | ## Student Management System 276 | - 1. Add Student 277 | - 2. Remove Student 278 | - 3. Search Student 279 | - 4. Display All Students 280 | - 5. Exit 281 | - Select an option: 4 282 | 283 | ## No students currently in the system. 284 | 285 | - Student Management System 286 | - 1. Add Student 287 | - 2. Remove Student 288 | - 3. Search Student 289 | - 4. Display All Students 290 | - 5. Exit 291 | - Select an option: 5 292 | Exiting Student Management System. 293 | 294 | 295 | 296 | -------------------------------------------------------------------------------- /Task_1_Number_Game.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import java.util.Scanner; 3 | 4 | public class Task_1_Number_Game { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | Random random = new Random(); 9 | 10 | int minRange = 1; 11 | int maxRange = 100; 12 | int maxAttempts = 7; 13 | int score = 0; 14 | 15 | System.out.println("Welcome to the Number Guessing Game!\n"); 16 | boolean playAgain = true; 17 | 18 | while (playAgain) { 19 | int targetNumber = random.nextInt(maxRange - minRange + 1) + minRange; 20 | System.out.printf("Round - Range: %d to %d\n", minRange, maxRange); 21 | System.out.println("You have " + maxAttempts + " attempts.\n"); 22 | 23 | int attempts = 0; 24 | boolean guessedCorrectly = false; 25 | 26 | while (attempts < maxAttempts) { 27 | System.out.print("Enter your guess: "); 28 | int userGuess = scanner.nextInt(); 29 | 30 | attempts++; 31 | 32 | if (userGuess == targetNumber) { 33 | System.out.printf("Correct! You guessed the number in %d attempts.\n", attempts); 34 | score += attempts; 35 | guessedCorrectly = true; 36 | break; 37 | } else if (userGuess < targetNumber) { 38 | System.out.println("Too low! Try again.\n"); 39 | } else { 40 | System.out.println("Too high! Try again.\n"); 41 | } 42 | } 43 | 44 | if (!guessedCorrectly) { 45 | System.out.println("Sorry, you've used all your attempts. The correct number was " + targetNumber); 46 | } 47 | 48 | System.out.println("Your current score: " + score + "\n"); 49 | 50 | System.out.print("Do you want to play another round? (yes/no): "); 51 | String playAgainResponse = scanner.next().toLowerCase(); 52 | if (!playAgainResponse.equals("yes")) { 53 | playAgain = false; 54 | } 55 | } 56 | 57 | System.out.println("Thank you for playing! Your final score: " + score); 58 | 59 | scanner.close(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Task_2_Student_Grade_Calculator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Task_2_Student_Grade_Calculator { 4 | 5 | public static void main(String[] args) { 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | System.out.print("Enter the number of subjects: "); 9 | int numOfSubjects = scanner.nextInt(); 10 | 11 | int totalMarks = 0; 12 | for (int i = 1; i <= numOfSubjects; i++) { 13 | System.out.print("Enter marks obtained in subject " + i + ": "); 14 | int marks = scanner.nextInt(); 15 | totalMarks += marks; 16 | } 17 | 18 | double averagePercentage = (double) totalMarks / numOfSubjects; 19 | 20 | char grade; 21 | if (averagePercentage >= 90) { 22 | grade = 'A'; 23 | } else if (averagePercentage >= 80) { 24 | grade = 'B'; 25 | } else if (averagePercentage >= 70) { 26 | grade = 'C'; 27 | } else if (averagePercentage >= 60) { 28 | grade = 'D'; 29 | } else if (averagePercentage >= 50) { 30 | grade = 'E'; 31 | } else { 32 | grade = 'F'; 33 | } 34 | 35 | System.out.println("\nTotal Marks: " + totalMarks); 36 | System.out.println("Average Percentage: " + averagePercentage + "%"); 37 | System.out.println("Grade: " + grade); 38 | 39 | scanner.close(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Task_3_ATM_Interface.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class BankAccount { 4 | private double balance; 5 | 6 | public BankAccount(double initialBalance) { 7 | this.balance = initialBalance; 8 | } 9 | 10 | public double getBalance() { 11 | return balance; 12 | } 13 | 14 | public void deposit(double amount) { 15 | if (amount > 0) { 16 | balance += amount; 17 | System.out.println("Deposit of $" + amount + " successful. Current balance: $" + balance); 18 | } else { 19 | System.out.println("Invalid deposit amount."); 20 | } 21 | } 22 | 23 | public void withdraw(double amount) { 24 | if (amount > 0 && amount <= balance) { 25 | balance -= amount; 26 | System.out.println("Withdrawal of $" + amount + " successful. Current balance: $" + balance); 27 | } else { 28 | System.out.println("Invalid withdrawal amount or insufficient balance."); 29 | } 30 | } 31 | } 32 | 33 | class ATM { 34 | private BankAccount bankAccount; 35 | 36 | public ATM(BankAccount bankAccount) { 37 | this.bankAccount = bankAccount; 38 | } 39 | 40 | public void displayMenu() { 41 | System.out.println("ATM Menu:"); 42 | System.out.println("1. Check Balance"); 43 | System.out.println("2. Deposit"); 44 | System.out.println("3. Withdraw"); 45 | System.out.println("4. Exit"); 46 | } 47 | 48 | public void performTransaction(int choice, Scanner scanner) { 49 | switch (choice) { 50 | case 1: 51 | System.out.println("Current balance: $" + bankAccount.getBalance()); 52 | break; 53 | case 2: 54 | System.out.print("Enter deposit amount: $"); 55 | double depositAmount = scanner.nextDouble(); 56 | bankAccount.deposit(depositAmount); 57 | break; 58 | case 3: 59 | System.out.print("Enter withdrawal amount: $"); 60 | double withdrawalAmount = scanner.nextDouble(); 61 | bankAccount.withdraw(withdrawalAmount); 62 | break; 63 | case 4: 64 | System.out.println("Exiting ATM. Thank you!"); 65 | scanner.close(); 66 | System.exit(0); 67 | default: 68 | System.out.println("Invalid choice. Please select a valid option."); 69 | } 70 | } 71 | } 72 | 73 | public class Task_3_ATM_Interface { 74 | public static void main(String[] args) { 75 | Scanner scanner = new Scanner(System.in); 76 | 77 | System.out.print("Enter initial account balance: $"); 78 | double initialBalance = scanner.nextDouble(); 79 | BankAccount bankAccount = new BankAccount(initialBalance); 80 | 81 | ATM atm = new ATM(bankAccount); 82 | 83 | while (true) { 84 | atm.displayMenu(); 85 | System.out.print("Select an option: "); 86 | int choice = scanner.nextInt(); 87 | 88 | atm.performTransaction(choice, scanner); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Task_4_StudentCourseRegistrationSystem.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | import java.util.Scanner; 4 | 5 | class Course { 6 | private String courseCode; 7 | private String title; 8 | private String description; 9 | private int capacity; 10 | private String schedule; 11 | private int availableSlots; 12 | 13 | public Course(String courseCode, String title, String description, int capacity, String schedule) { 14 | this.courseCode = courseCode; 15 | this.title = title; 16 | this.description = description; 17 | this.capacity = capacity; 18 | this.schedule = schedule; 19 | this.availableSlots = capacity; 20 | } 21 | 22 | public String getCourseCode() { 23 | return courseCode; 24 | } 25 | 26 | public String getTitle() { 27 | return title; 28 | } 29 | 30 | public String getDescription() { 31 | return description; 32 | } 33 | 34 | public int getAvailableSlots() { 35 | return availableSlots; 36 | } 37 | 38 | public boolean registerStudent() { 39 | if (availableSlots > 0) { 40 | availableSlots--; 41 | return true; 42 | } 43 | return false; 44 | } 45 | 46 | public void dropStudent() { 47 | if (availableSlots < capacity) { 48 | availableSlots++; 49 | } 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Course Code: " + courseCode + 55 | "\nTitle: " + title + 56 | "\nDescription: " + description + 57 | "\nSchedule: " + schedule + 58 | "\nAvailable Slots: " + availableSlots + "/" + capacity + "\n"; 59 | } 60 | } 61 | 62 | class Student { 63 | private int studentID; 64 | private String name; 65 | private List registeredCourses; 66 | 67 | public Student(int studentID, String name) { 68 | this.studentID = studentID; 69 | this.name = name; 70 | this.registeredCourses = new ArrayList<>(); 71 | } 72 | 73 | public int getStudentID() { 74 | return studentID; 75 | } 76 | 77 | public String getName() { 78 | return name; 79 | } 80 | 81 | public List getRegisteredCourses() { 82 | return registeredCourses; 83 | } 84 | 85 | public void registerCourse(Course course) { 86 | if (course.registerStudent()) { 87 | registeredCourses.add(course); 88 | } 89 | } 90 | 91 | public void dropCourse(Course course) { 92 | course.dropStudent(); 93 | registeredCourses.remove(course); 94 | } 95 | 96 | @Override 97 | public String toString() { 98 | StringBuilder coursesList = new StringBuilder(); 99 | for (Course course : registeredCourses) { 100 | coursesList.append(course.getTitle()).append(", "); 101 | } 102 | return "Student ID: " + studentID + 103 | "\nName: " + name + 104 | "\nRegistered Courses: " + (coursesList.length() > 0 ? coursesList.substring(0, coursesList.length() - 2) : "None") + "\n"; 105 | } 106 | } 107 | 108 | public class Task_4_StudentCourseRegistrationSystem { 109 | private List students; 110 | private List courses; 111 | 112 | public Task_4_StudentCourseRegistrationSystem() { 113 | students = new ArrayList<>(); 114 | courses = new ArrayList<>(); 115 | } 116 | 117 | public void addStudent(Student student) { 118 | students.add(student); 119 | } 120 | 121 | public void addCourse(Course course) { 122 | courses.add(course); 123 | } 124 | 125 | public Course findCourseByCode(String courseCode) { 126 | for (Course course : courses) { 127 | if (course.getCourseCode().equals(courseCode)) { 128 | return course; 129 | } 130 | } 131 | return null; 132 | } 133 | 134 | public Student findStudentByID(int studentID) { 135 | for (Student student : students) { 136 | if (student.getStudentID() == studentID) { 137 | return student; 138 | } 139 | } 140 | return null; 141 | } 142 | 143 | public static void main(String[] args) { 144 | Scanner scanner = new Scanner(System.in); 145 | Task_4_StudentCourseRegistrationSystem system = new Task_4_StudentCourseRegistrationSystem(); 146 | 147 | // Add initial students and courses here 148 | system.addStudent(new Student(1, "John Doe")); 149 | system.addStudent(new Student(2, "Jane Smith")); 150 | system.addCourse(new Course("CS101", "Introduction to Programming", "Learn the basics of programming", 50, "Mon, Wed 9:00 AM - 10:30 AM")); 151 | system.addCourse(new Course("MATH202", "Advanced Mathematics", "Advanced math concepts", 40, "Tue, Thu 11:00 AM - 12:30 PM")); 152 | 153 | while (true) { 154 | System.out.println("Student Course Registration System"); 155 | System.out.println("1. Register Course"); 156 | System.out.println("2. Drop Course"); 157 | System.out.println("3. Display Student Info"); 158 | System.out.println("4. Exit"); 159 | System.out.print("Select an option: "); 160 | 161 | int choice = scanner.nextInt(); 162 | scanner.nextLine(); // Consume newline 163 | 164 | switch (choice) { 165 | case 1: 166 | System.out.print("Enter Student ID: "); 167 | int studentID = scanner.nextInt(); 168 | scanner.nextLine(); // Consume newline 169 | System.out.print("Enter Course Code: "); 170 | String courseCode = scanner.nextLine(); 171 | Student student = system.findStudentByID(studentID); 172 | Course course = system.findCourseByCode(courseCode); 173 | if (student != null && course != null) { 174 | student.registerCourse(course); 175 | System.out.println("Course registered successfully."); 176 | } else { 177 | System.out.println("Student or course not found."); 178 | } 179 | break; 180 | case 2: 181 | System.out.print("Enter Student ID: "); 182 | int studentIDDrop = scanner.nextInt(); 183 | scanner.nextLine(); // Consume newline 184 | System.out.print("Enter Course Code: "); 185 | String courseCodeDrop = scanner.nextLine(); 186 | Student studentDrop = system.findStudentByID(studentIDDrop); 187 | Course courseDrop = system.findCourseByCode(courseCodeDrop); 188 | if (studentDrop != null && courseDrop != null) { 189 | studentDrop.dropCourse(courseDrop); 190 | System.out.println("Course dropped successfully."); 191 | } else { 192 | System.out.println("Student or course not found."); 193 | } 194 | break; 195 | case 3: 196 | System.out.print("Enter Student ID: "); 197 | int studentIDInfo = scanner.nextInt(); 198 | Student studentInfo = system.findStudentByID(studentIDInfo); 199 | if (studentInfo != null) { 200 | System.out.println("Student Info:\n" + studentInfo); 201 | } else { 202 | System.out.println("Student not found."); 203 | } 204 | break; 205 | case 4: 206 | System.out.println("Exiting Student Course Registration System."); 207 | scanner.close(); 208 | System.exit(0); 209 | default: 210 | System.out.println("Invalid choice. Please select a valid option."); 211 | } 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /Task_5_Student_management_system.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.ArrayList; 3 | import java.util.List; 4 | import java.util.Scanner; 5 | 6 | class Student { 7 | private String name; 8 | private int rollNumber; 9 | private String grade; 10 | 11 | public Student(String name, int rollNumber, String grade) { 12 | this.name = name; 13 | this.rollNumber = rollNumber; 14 | this.grade = grade; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public int getRollNumber() { 22 | return rollNumber; 23 | } 24 | 25 | public String getGrade() { 26 | return grade; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Name: " + name + "\nRoll Number: " + rollNumber + "\nGrade: " + grade + "\n"; 32 | } 33 | } 34 | 35 | class StudentManagementSystem { 36 | private List students; 37 | 38 | public StudentManagementSystem() { 39 | students = new ArrayList<>(); 40 | } 41 | 42 | public void addStudent(Student student) { 43 | students.add(student); 44 | } 45 | 46 | public void removeStudent(int rollNumber) { 47 | students.removeIf(student -> student.getRollNumber() == rollNumber); 48 | } 49 | 50 | public Student searchStudent(int rollNumber) { 51 | for (Student student : students) { 52 | if (student.getRollNumber() == rollNumber) { 53 | return student; 54 | } 55 | } 56 | return null; 57 | } 58 | 59 | public void displayAllStudents() { 60 | for (Student student : students) { 61 | System.out.println(student); 62 | } 63 | } 64 | 65 | public void saveStudentDataToFile(String filename) { 66 | try (PrintWriter writer = new PrintWriter(new FileWriter(filename))) { 67 | for (Student student : students) { 68 | writer.println(student.getName() + "," + student.getRollNumber() + "," + student.getGrade()); 69 | } 70 | System.out.println("Student data saved to " + filename); 71 | } catch (IOException e) { 72 | System.out.println("Error saving student data to file: " + e.getMessage()); 73 | } 74 | } 75 | 76 | public void loadStudentDataFromFile(String filename) { 77 | students.clear(); 78 | try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { 79 | String line; 80 | while ((line = reader.readLine()) != null) { 81 | String[] parts = line.split(","); 82 | if (parts.length == 3) { 83 | String name = parts[0]; 84 | int rollNumber = Integer.parseInt(parts[1]); 85 | String grade = parts[2]; 86 | students.add(new Student(name, rollNumber, grade)); 87 | } 88 | } 89 | System.out.println("Student data loaded from " + filename); 90 | } catch (IOException e) { 91 | System.out.println("Error loading student data from file: " + e.getMessage()); 92 | } 93 | } 94 | } 95 | 96 | public class Task_5_Student_management_system { 97 | public static void main(String[] args) { 98 | Scanner scanner = new Scanner(System.in); 99 | StudentManagementSystem system = new StudentManagementSystem(); 100 | 101 | while (true) { 102 | System.out.println("Student Management System"); 103 | System.out.println("1. Add Student"); 104 | System.out.println("2. Remove Student"); 105 | System.out.println("3. Search Student"); 106 | System.out.println("4. Display All Students"); 107 | System.out.println("5. Save Student Data"); 108 | System.out.println("6. Load Student Data"); 109 | System.out.println("7. Exit"); 110 | System.out.print("Select an option: "); 111 | 112 | int choice = scanner.nextInt(); 113 | scanner.nextLine(); // Consume newline 114 | 115 | switch (choice) { 116 | case 1: 117 | System.out.print("Enter student name: "); 118 | String name = scanner.nextLine(); 119 | System.out.print("Enter roll number: "); 120 | int rollNumber = scanner.nextInt(); 121 | scanner.nextLine(); // Consume newline 122 | System.out.print("Enter grade: "); 123 | String grade = scanner.nextLine(); 124 | system.addStudent(new Student(name, rollNumber, grade)); 125 | break; 126 | case 2: 127 | System.out.print("Enter roll number of student to remove: "); 128 | int rollNumberToRemove = scanner.nextInt(); 129 | system.removeStudent(rollNumberToRemove); 130 | break; 131 | case 3: 132 | System.out.print("Enter roll number of student to search: "); 133 | int rollNumberToSearch = scanner.nextInt(); 134 | Student searchedStudent = system.searchStudent(rollNumberToSearch); 135 | if (searchedStudent != null) { 136 | System.out.println("Student found:\n" + searchedStudent); 137 | } else { 138 | System.out.println("Student not found."); 139 | } 140 | break; 141 | case 4: 142 | System.out.println("All Students:"); 143 | system.displayAllStudents(); 144 | break; 145 | case 5: 146 | System.out.print("Enter filename to save student data: "); 147 | String saveFilename = scanner.nextLine(); 148 | system.saveStudentDataToFile(saveFilename); 149 | break; 150 | case 6: 151 | System.out.print("Enter filename to load student data: "); 152 | String loadFilename = scanner.nextLine(); 153 | system.loadStudentDataFromFile(loadFilename); 154 | break; 155 | case 7: 156 | System.out.println("Exiting Student Management System. Goodbye!"); 157 | scanner.close(); 158 | System.exit(0); 159 | default: 160 | System.out.println("Invalid choice. Please select a valid option."); 161 | } 162 | } 163 | } 164 | } 165 | --------------------------------------------------------------------------------