Java:ECC(纠错码)库?

发布于 2024-09-03 08:26:24 字数 71 浏览 8 评论 0原文

是否有一个众所周知的 Java 的 ECC(纠错码)库(例如 Reed-Solomon)实现,具有友好的开源许可(非 GPL)?

Is there a well-known implementation, that has friendly open-source licensing (not GPL), of an ECC (error correcting code) library (e.g. Reed-Solomon) for Java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

错爱 2024-09-10 08:26:24

zxing

Apache 许可证(不确定这是否符合您对友好的定义)我也不确定是否如此算众所周知(谷歌知道这一点,“java Reed-Solomon”没有 2 个结果)?

zxing

Apache License (not sure if that counts in your definition of friendly) I am also not sure if it counts as well known (google knew about it, no 2 result for "java Reed-Solomon")?

烟酒忠诚 2024-09-10 08:26:24

我已经为 Plank 等人编写的 JErasure 库实现了 Java 包装器。 。

如果您不介意本机依赖性,那么 JErasure 是一个很好的选择(如果不是最好的) 在有人将 JErasure 移植到 Java 之前,您将不得不简化性能,因为在处理较大的数据块时,zxing 中的实现速度并不那么快。

我已将代码放在 GitHub 上: https://github.com/jvandertil/Jerasure

I have implemented Java wrappers for the JErasure Library written by Plank et al. in C.

If you do not mind the native dependency, then JErasure is an excellent choice (if not the best). Until someone ports JErasure to Java, you will have to concise on performance as the implementation in zxing is not that fast when working on larger blocks of data.

I have put the code on GitHub: https://github.com/jvandertil/Jerasure

寻找我们的幸福 2024-09-10 08:26:24
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Student {
    private String ID;
    private String name;
    private int age;
    private List<Course> enrolledCourses;

    public Student(String ID, String name, int age) {
        this.ID = ID;
        this.name = name;
        this.age = age;
        this.enrolledCourses = new ArrayList<>();
    }

    public void enrollCourse(Course course) {
        enrolledCourses.add(course);
    }

    public void viewCourseDetails() {
        System.out.println("Enrolled courses:");
        for (Course course : enrolledCourses) {
            System.out.println(course.getName());
        }
    }

    public void viewGrades() {
        System.out.println("Grades for enrolled courses:");
        for (Course course : enrolledCourses) {
            System.out.println("Course: " + course.getName() + ", Grade: " + course.getGrade(this));
        }
    }
}

class Instructor {
    private String ID;
    private String name;
    private int age;
    private List<Course> taughtCourses;

    public Instructor(String ID, String name, int age) {
        this.ID = ID;
        this.name = name;
        this.age = age;
        this.taughtCourses = new ArrayList<>();
    }

    public void assignCourse(Course course) {
        taughtCourses.add(course);
    }

    public void viewEnrolledStudents(Course course) {
        List<Student> enrolledStudents = course.getEnrolledStudents();
        System.out.println("Enrolled students in " + course.getName() + ":");
        for (Student student : enrolledStudents) {
            System.out.println(student.getName());
        }
    }
}

class Course {
    private String courseCode;
    private String name;
    private Instructor instructor;
    private List<Student> enrolledStudents;
    private Map<Student, Integer> grades;

    public Course(String courseCode, String name, Instructor instructor) {
        this.courseCode = courseCode;
        this.name = name;
        this.instructor = instructor;
        this.enrolledStudents = new ArrayList<>();
        this.grades = new HashMap<>();
    }

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

    public void setInstructor(Instructor instructor) {
        this.instructor = instructor;
    }

    public void addGrade(Student student, int grade) {
        grades.put(student, grade);
    }

    public int getGrade(Student student) {
        Integer grade = grades.get(student);
        return (grade != null) ? grade : -1; // Return -1 if grade not found
    }

    public double calculateAverageGrade() {
        int totalGrades = 0;
        for (int grade : grades.values()) {
            totalGrades += grade;
        }
        return (grades.size() > 0) ? (double) totalGrades / grades.size() : 0;
    }

    public String getName() {
        return name;
    }

    public List<Student> getEnrolledStudents() {
        return enrolledStudents;
    }
}

class StudentManagementSystem {
    private List<Student> students;
    private List<Instructor> instructors;
    private List<Course> courses;
    private Scanner scanner;

    public StudentManagementSystem() {
        students = new ArrayList<>();
        instructors = new ArrayList<>();
        courses = new ArrayList<>();
        scanner = new Scanner(System.in);
    }

    public void addStudent() {
        System.out.print("Enter student ID: ");
        String ID = scanner.nextLine();
        System.out.print("Enter student name: ");
        String name = scanner.nextLine();
        System.out.print("Enter student age: ");
        int age = Integer.parseInt(scanner.nextLine());

        Student student = new Student(ID, name, age);
        students.add(student);
        System.out.println("Student added successfully.");
    }

    public void addInstructor() {
        System.out.print("Enter instructor ID: ");
        String ID = scanner.nextLine();
        System.out.print("Enter instructor name: ");
        String name = scanner.nextLine();
        System.out.print("Enter instructor age: ");
        int age = Integer.parseInt(scanner.nextLine());

        Instructor instructor = new Instructor(ID, name, age);
        instructors.add(instructor);
        System.out.println("Instructor added successfully.");
    }

    public void enrollStudentInCourse() {
        System.out.print("Enter student ID: ");
        String studentID = scanner.nextLine();
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Student student = getStudentByID(studentID);
        Course course = getCourseByCode(courseCode);

        if (student != null && course != null) {
            student.enrollCourse(course);
            course.addStudent(student);
            System.out.println("Student enrolled in the course successfully.");
        } else {
            System.out.println("Invalid student ID or course code.");
        }
    }

    public void assignInstructorToCourse() {
        System.out.print("Enter instructor ID: ");
        String instructorID = scanner.nextLine();
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Instructor instructor = getInstructorByID(instructorID);
        Course course = getCourseByCode(courseCode);

        if (instructor != null && course != null) {
            instructor.assignCourse(course);
            course.setInstructor(instructor);
            System.out.println("Instructor assigned to the course successfully.");
        } else {
            System.out.println("Invalid instructor ID or course code.");
        }
    }

    public void viewCourseDetails() {
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Course course = getCourseByCode(courseCode);

        if (course != null) {
            System.out.println("Course: " + course.getName());
            System.out.println("Instructor: " + course.getInstructor().getName());
            System.out.println("Average Grade: " + course.calculateAverageGrade());
        } else {
            System.out.println("Course not found.");
        }
    }

    public void viewEnrolledStudents() {
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Course course = getCourseByCode(courseCode);

        if (course != null) {
            course.getInstructor().viewEnrolledStudents(course);
        } else {
            System.out.println("Course not found.");
        }
    }

    public Student getStudentByID(String studentID) {
        for (Student student : students) {
            if (student.getID().equals(studentID)) {
                return student;
            }
        }
        return null;
    }

    public Instructor getInstructorByID(String instructorID) {
        for (Instructor instructor : instructors) {
            if (instructor.getID().equals(instructorID)) {
                return instructor;
            }
        }
        return null;
    }

    public Course getCourseByCode(String courseCode) {
        for (Course course : courses) {
            if (course.getCourseCode().equals(courseCode)) {
                return course;
            }
        }
        return null;
    }

    public void run() {
        while (true) {
            System.out.println("\n***** Student Management System Menu *****");
            System.out.println("1. Add a new student");
            System.out.println("2. Add a new instructor");
            System.out.println("3. Enroll a student in a course");
            System.out.println("4. Assign an instructor to a course");
            System.out.println("5. View course details and average grades");
            System.out.println("6. View the list of students enrolled in a course");
            System.out.println("0. Exit");

            System.out.print("Enter your choice: ");
            int choice = Integer.parseInt(scanner.nextLine());

            switch (choice) {
                case 1:
                    addStudent();
                    break;
                case 2:
                    addInstructor();
                    break;
                case 3:
                    enrollStudentInCourse();
                    break;
                case 4:
                    assignInstructorToCourse();
                    break;
                case 5:
                    viewCourseDetails();
                    break;
                case 6:
                    viewEnrolledStudents();
                    break;
                case 0:
                    System.out.println("Exiting Student Management System. Goodbye!");
                    System.exit(0);
                    break;
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }

    public static void main(String[] args) {
        StudentManagementSystem system = new StudentManagementSystem();
        system.run();
    }
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Student {
    private String ID;
    private String name;
    private int age;
    private List<Course> enrolledCourses;

    public Student(String ID, String name, int age) {
        this.ID = ID;
        this.name = name;
        this.age = age;
        this.enrolledCourses = new ArrayList<>();
    }

    public void enrollCourse(Course course) {
        enrolledCourses.add(course);
    }

    public void viewCourseDetails() {
        System.out.println("Enrolled courses:");
        for (Course course : enrolledCourses) {
            System.out.println(course.getName());
        }
    }

    public void viewGrades() {
        System.out.println("Grades for enrolled courses:");
        for (Course course : enrolledCourses) {
            System.out.println("Course: " + course.getName() + ", Grade: " + course.getGrade(this));
        }
    }
}

class Instructor {
    private String ID;
    private String name;
    private int age;
    private List<Course> taughtCourses;

    public Instructor(String ID, String name, int age) {
        this.ID = ID;
        this.name = name;
        this.age = age;
        this.taughtCourses = new ArrayList<>();
    }

    public void assignCourse(Course course) {
        taughtCourses.add(course);
    }

    public void viewEnrolledStudents(Course course) {
        List<Student> enrolledStudents = course.getEnrolledStudents();
        System.out.println("Enrolled students in " + course.getName() + ":");
        for (Student student : enrolledStudents) {
            System.out.println(student.getName());
        }
    }
}

class Course {
    private String courseCode;
    private String name;
    private Instructor instructor;
    private List<Student> enrolledStudents;
    private Map<Student, Integer> grades;

    public Course(String courseCode, String name, Instructor instructor) {
        this.courseCode = courseCode;
        this.name = name;
        this.instructor = instructor;
        this.enrolledStudents = new ArrayList<>();
        this.grades = new HashMap<>();
    }

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

    public void setInstructor(Instructor instructor) {
        this.instructor = instructor;
    }

    public void addGrade(Student student, int grade) {
        grades.put(student, grade);
    }

    public int getGrade(Student student) {
        Integer grade = grades.get(student);
        return (grade != null) ? grade : -1; // Return -1 if grade not found
    }

    public double calculateAverageGrade() {
        int totalGrades = 0;
        for (int grade : grades.values()) {
            totalGrades += grade;
        }
        return (grades.size() > 0) ? (double) totalGrades / grades.size() : 0;
    }

    public String getName() {
        return name;
    }

    public List<Student> getEnrolledStudents() {
        return enrolledStudents;
    }
}

class StudentManagementSystem {
    private List<Student> students;
    private List<Instructor> instructors;
    private List<Course> courses;
    private Scanner scanner;

    public StudentManagementSystem() {
        students = new ArrayList<>();
        instructors = new ArrayList<>();
        courses = new ArrayList<>();
        scanner = new Scanner(System.in);
    }

    public void addStudent() {
        System.out.print("Enter student ID: ");
        String ID = scanner.nextLine();
        System.out.print("Enter student name: ");
        String name = scanner.nextLine();
        System.out.print("Enter student age: ");
        int age = Integer.parseInt(scanner.nextLine());

        Student student = new Student(ID, name, age);
        students.add(student);
        System.out.println("Student added successfully.");
    }

    public void addInstructor() {
        System.out.print("Enter instructor ID: ");
        String ID = scanner.nextLine();
        System.out.print("Enter instructor name: ");
        String name = scanner.nextLine();
        System.out.print("Enter instructor age: ");
        int age = Integer.parseInt(scanner.nextLine());

        Instructor instructor = new Instructor(ID, name, age);
        instructors.add(instructor);
        System.out.println("Instructor added successfully.");
    }

    public void enrollStudentInCourse() {
        System.out.print("Enter student ID: ");
        String studentID = scanner.nextLine();
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Student student = getStudentByID(studentID);
        Course course = getCourseByCode(courseCode);

        if (student != null && course != null) {
            student.enrollCourse(course);
            course.addStudent(student);
            System.out.println("Student enrolled in the course successfully.");
        } else {
            System.out.println("Invalid student ID or course code.");
        }
    }

    public void assignInstructorToCourse() {
        System.out.print("Enter instructor ID: ");
        String instructorID = scanner.nextLine();
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Instructor instructor = getInstructorByID(instructorID);
        Course course = getCourseByCode(courseCode);

        if (instructor != null && course != null) {
            instructor.assignCourse(course);
            course.setInstructor(instructor);
            System.out.println("Instructor assigned to the course successfully.");
        } else {
            System.out.println("Invalid instructor ID or course code.");
        }
    }

    public void viewCourseDetails() {
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Course course = getCourseByCode(courseCode);

        if (course != null) {
            System.out.println("Course: " + course.getName());
            System.out.println("Instructor: " + course.getInstructor().getName());
            System.out.println("Average Grade: " + course.calculateAverageGrade());
        } else {
            System.out.println("Course not found.");
        }
    }

    public void viewEnrolledStudents() {
        System.out.print("Enter course code: ");
        String courseCode = scanner.nextLine();

        Course course = getCourseByCode(courseCode);

        if (course != null) {
            course.getInstructor().viewEnrolledStudents(course);
        } else {
            System.out.println("Course not found.");
        }
    }

    public Student getStudentByID(String studentID) {
        for (Student student : students) {
            if (student.getID().equals(studentID)) {
                return student;
            }
        }
        return null;
    }

    public Instructor getInstructorByID(String instructorID) {
        for (Instructor instructor : instructors) {
            if (instructor.getID().equals(instructorID)) {
                return instructor;
            }
        }
        return null;
    }

    public Course getCourseByCode(String courseCode) {
        for (Course course : courses) {
            if (course.getCourseCode().equals(courseCode)) {
                return course;
            }
        }
        return null;
    }

    public void run() {
        while (true) {
            System.out.println("\n***** Student Management System Menu *****");
            System.out.println("1. Add a new student");
            System.out.println("2. Add a new instructor");
            System.out.println("3. Enroll a student in a course");
            System.out.println("4. Assign an instructor to a course");
            System.out.println("5. View course details and average grades");
            System.out.println("6. View the list of students enrolled in a course");
            System.out.println("0. Exit");

            System.out.print("Enter your choice: ");
            int choice = Integer.parseInt(scanner.nextLine());

            switch (choice) {
                case 1:
                    addStudent();
                    break;
                case 2:
                    addInstructor();
                    break;
                case 3:
                    enrollStudentInCourse();
                    break;
                case 4:
                    assignInstructorToCourse();
                    break;
                case 5:
                    viewCourseDetails();
                    break;
                case 6:
                    viewEnrolledStudents();
                    break;
                case 0:
                    System.out.println("Exiting Student Management System. Goodbye!");
                    System.exit(0);
                    break;
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }

    public static void main(String[] args) {
        StudentManagementSystem system = new StudentManagementSystem();
        system.run();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文