Menu
Question Index
...


Write a program to parse the comma separated student information and create Student objects for each line of the data. The list of students should be sorted first by section and then by the name.

class ParseAndSortStudents

{    public static void main(String s[])
    {
        String data = "Siva,2,78,A\n";
        data += "Mobeen,3,92,B\n";
        data += "Prem,2,87,B\n";
        data += "Sasitha,2,86,A\n";
        data += "Srini,8,65,A\n";
        data += "Zakir,12,73,A\n";
        
        List result = parseAndSortStudents(data);
        
        for(int i = 0; i < result.size(); i++)
        {
            Student student = result.get(i);
            System.out.println(student.name + " in section " + student.section + " and roll number " + student.rollNumber + " got " + student.marks + " marks.");
        }

    }


public static List<Student> parseAndSortStudents(String data)
{
//Write code here to the parse the comma separated data and create the Student objects
}
}
class Student
{
String name;
int rollNumber;
int marks;
char section;

Student(String name, int rollNumber, int marks, char section)
{
this.name = name;
this.rollNumber = rollNumber;
this.marks = marks;
this.section = section;
}
}

Doubts

Problems

Topic: Java Comparators

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App