Convert From Comma Delimited Format To Section Object - Java Quiz Question



Write a program to convert from comma delimited format to section object.

Input(String) (New lines are shown as $ for display purpose) Output(Section Object)
MPC,Suraj,2$Raju,1,98,76.5,M$Mohini,2,88,92.5,F$ sectionName = MPC
classTeacher = Suraj
numberOfStudents = 2
1st Student : Raju : 1 : 98 : 76.5 : M
2nd Student : Mohini : 2 : 88 : 92.5 : F
BiPC,Rama S,3$Padmaja,10,78,92.5,F$Sunitha,12,65,75.0,F$Krishna,15,87,70,M$ sectionName = BiPC
classTeacher = 'Rama S'
numberOfStudents = 3
1st Student : Padmaja : 10 : 78 : 92.5 : F
2nd Student : Sunitha : 12 : 65 : 75.0 : F
3rd Student : Krishna : 15 : 87 : 70 : M
HEC,Lavanya M,1$Venkatesh,1,100,99.9,M$ sectionName = HEC
classTeacher = 'Lavanya M'
numberOfStudents = 1
1st Student : Venkatesh : 1 : 100 : 99.9 : M

class ConvertDelimitedFormatToSection

{    public static void main(String s[])
    {
        String input = "MPC,Suraj,2\nRaju,1,98,76.5,M\nMohini,2,88,92.5,F\n";
        Section section = convertToSection(input);
        String result = "";
        result += section.sectionName + " : ";
        result += section.classTeacher + " : ";
        result += section.numberOfStudents + "\n";
        result += section.getStudents();
        System.out.println("The section details are : \n" + result);

    }


public static Section convertToSection(String str) {
//Write code here to delimited format to section object.
}
}
class Section {

String sectionName;
String classTeacher;
int numberOfStudents;
ArrayList<Student> students = new ArrayList<Student>();

public Section(String sectionName, String classTeacher, int numberOfstudents) {
this.sectionName = sectionName;
this.classTeacher = classTeacher;
numberOfStudents = numberOfstudents;
}

public String getStudents() {
String result = "";
for (int i = 0; i < students.size(); i++) {
result += students.get(i) + "\n";
}
return result;
}
}

class Student {

String name;
int roll_number;
int marks;
double percentage;
char gender;

public String toString() {
return name + " : " + roll_number + " : " + marks + " : " + percentage + " : " + gender;
}
}