Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Teacher - Student Software

Teacher - Student Software

Let's create a simple Teacher-Student management software in Java. This software will allow you to add and manage teachers and students, as well as assign students to teachers. Here's an example implementation to get you started:

```java
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Teacher {
    private String name;
    private List<Student> students;

    public Teacher(String name) {
        this.name = name;
        this.students = new ArrayList<>();
    }

    public String getName() {
        return name;
    }

    public void addStudent(Student student) {
        students.add(student);
    }

    public List<Student> getStudents() {
        return students;
    }
}

class Student {
    private String name;

    public Student(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}

public class TeacherStudentManagement {
    private List<Teacher> teachers;
    private List<Student> students;

    public TeacherStudentManagement() {
        this.teachers = new ArrayList<>();
        this.students = new ArrayList<>();
    }

    public void addTeacher(String name) {
        Teacher teacher = new Teacher(name);
        teachers.add(teacher);
        System.out.println("Teacher added: " + name);
    }

    public void addStudent(String name) {
        Student student = new Student(name);
        students.add(student);
        System.out.println("Student added: " + name);
    }

    public void assignStudentToTeacher(String studentName, String teacherName) {
        Student student = findStudent(studentName);
        Teacher teacher = findTeacher(teacherName);

        if (student != null && teacher != null) {
            teacher.addStudent(student);
            System.out.println(studentName + " assigned to " + teacherName);
        } else {
            System.out.println("Student or teacher not found.");
        }
    }

    public void displayTeacherStudents(String teacherName) {
        Teacher teacher = findTeacher(teacherName);

        if (teacher != null) {
            List<Student> students = teacher.getStudents();
            System.out.println("Students assigned to " + teacherName + ":");
            for (Student student : students) {
                System.out.println(student.getName());
            }
        } else {
            System.out.println("Teacher not found.");
        }
    }

    private Student findStudent(String name) {
        for (Student student : students) {
            if (student.getName().equals(name)) {
                return student;
            }
        }
        return null;
    }

    private Teacher findTeacher(String name) {
        for (Teacher teacher : teachers) {
            if (teacher.getName().equals(name)) {
                return teacher;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        TeacherStudentManagement management = new TeacherStudentManagement();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("Teacher-Student Management");
            System.out.println("1. Add Teacher");
            System.out.println("2. Add Student");
            System.out.println("3. Assign Student to Teacher");
            System.out.println("4. Display Students of a Teacher");
            System.out.println("5. Exit");
            System.out.print("Enter your choice: ");
            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.print("Enter teacher name: ");
                    String teacherName = scanner.next();
                    management.addTeacher(teacherName);
                    break;
                case 2:
                    System.out.print("Enter student name: ");
                    String studentName = scanner.next();
                    management.addStudent(studentName);
                    break;
                case 3:
                    System.out.print("Enter student name: ");
                    String student

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.